You are here:   Home
  |  Login
DotNetNuke Core Team
Microsoft MVP
 Bookmark this article!
delicious.com delicious.com
digg digg
technorati technorati
reddit reddit
stumbleupon stumbleupon
facebook facebook
google bookmarks google bookmarks
yahoo bookmarks yahoo bookmarks
slashdot slashdot
live live
twitter twitter
DotNetKicks DotNetKicks

Tags

  1. 1 items are tagged with Admin settings
  2. 1 items are tagged with AJAX Extensions
  3. 1 items are tagged with ASP.NET
  4. 2 items are tagged with BBeyond
  5. 1 items are tagged with Caching
  6. 1 items are tagged with Cambrian
  7. 1 items are tagged with CBO
  8. 2 items are tagged with Codeplex
  9. 1 items are tagged with debugging
  10. 1 items are tagged with DotNetNuke
  11. 2 items are tagged with DotNetNuke 5
  12. 1 items are tagged with email validation
  13. 1 items are tagged with Google
  14. 1 items are tagged with IBaseEntity
  15. 2 items are tagged with IdentitySwitcher
  16. 1 items are tagged with IHydratable
  17. 1 items are tagged with Inline Skin Object
  18. 2 items are tagged with Installation
  19. 1 items are tagged with Installer
  20. 1 items are tagged with intellisense
  21. 1 items are tagged with IPropertyAccess
  22. 1 items are tagged with Language
  23. 1 items are tagged with Manifest
  24. 1 items are tagged with moving
  25. 1 items are tagged with OpenForce
  26. 1 items are tagged with Permissions
  27. 1 items are tagged with Profile Properties
  28. 1 items are tagged with PropertyEditorControl
  29. 1 items are tagged with recent projects
  30. 1 items are tagged with regex
  31. 1 items are tagged with Sample Module
  32. 1 items are tagged with Search Results
  33. 2 items are tagged with Skin Object
  34. 1 items are tagged with Skinning
  35. 6 items are tagged with SQL
  36. 1 items are tagged with SQL Server
  37. 1 items are tagged with SQL Server 2008
  38. 1 items are tagged with Table Functions
  39. 2 items are tagged with TellCo
  40. 1 items are tagged with TokenReplace
  41. 2 items are tagged with Too Good to be True
  42. 1 items are tagged with Twitter
  43. 2 items are tagged with UPC
  44. 2 items are tagged with Upgrading
  45. 1 items are tagged with Users
  46. 2 items are tagged with visual studio
  47. 1 items are tagged with Visual Studio 2008

My Twitter Feed...

Fri, 05 Mar 2010 09:25:30 +0100

erikvb: @schotman you probably ran into this already? http://www.simonblog.com/2008/11/14/qr-code-reader-for-iphone-barcodes-zxing/

Wed, 03 Mar 2010 16:22:05 +0100

erikvb: @CuongDang @WillStrohl btw: another reason to use #mixero: it has a global filter

Wed, 03 Mar 2010 15:57:33 +0100

erikvb: @WillStrohl @CuongDang #foursuare yep.. just look at http://pleaserobme.com

Tue, 02 Mar 2010 11:39:20 +0100

erikvb: ok this is weird...RT @cnnbrk: Chile quake might have shortened days on Earth http://on.cnn.com/b3V8Mq

Sat, 27 Feb 2010 11:25:22 +0100

erikvb: @aafvstam its almost 2012 :)

Sat, 27 Feb 2010 11:24:44 +0100

erikvb: RT @superska: Did I mention we (@erikvb @pdonker @superska) kicked off the new Dutch spoken DNN Usergroup today? http://www.dnngg.nl #mv ...

Fri, 26 Feb 2010 22:23:00 +0100

erikvb: fiasco

Fri, 26 Feb 2010 22:19:17 +0100

erikvb: @TimoBreumelhof #Sauerbreij fat chance.. niet zolang mart smeets de dienst uitmaakt

Fri, 26 Feb 2010 22:09:39 +0100

erikvb: first alpine gold medal for the Netherlands #olympics #van2010

Fri, 26 Feb 2010 22:07:15 +0100

erikvb: yesss.. gold for nicolien!

Selecting profile properties the easy way

Last Updated 04/27/2009
By: Erik van Ballegoij

Every once and a while you probably find yourself needing to create an overview of DNN users and some of their profile properties. For instance when your client wants to have that data in an excel spreadsheet….

Profile properties in DNN are both a blessing and a curse. Although they allow you to quickly add attributes to a user, such as Companyname, Picture, etc., they are hard to use in SQL. That’s because of the structure of the data: there’s a table that holds all property definitions, and there’s another table that holds the data.

DNN Profile Properties

In the past, I have been using a quick and dirty way: just creating a specific view for each profile property I wanted to include in my select. That would work like this: let’s suppose I have a profile property named “CompanyName”. I can then create a view like this:

CREATE VIEW [dbo].[vwCompanyName]
AS
SELECT     UP.UserID, PPD.PortalID, UP.PropertyValue AS CompanyName
FROM         dbo.ProfilePropertyDefinition AS PPD INNER JOIN
                      dbo.UserProfile AS UP ON PPD.PropertyDefinitionID = UP.PropertyDefinitionID
WHERE     (PPD.PropertyName = 'CompanyName') AND (PPD.PortalID = 0)

 

This allows me to create a new view that includes the companyname with the user’s info:

CREATE VIEW [dbo].[vw_UsersComplete]
AS
SELECT     dbo.vw_Users.UserId, dbo.vw_Users.PortalId, dbo.vw_Users.Username, dbo.vw_Users.FirstName, dbo.vw_Users.LastName, 
                      dbo.vw_Users.DisplayName, dbo.vw_Users.IsSuperUser, dbo.vw_Users.Email, dbo.vw_Users.AffiliateId, dbo.vw_Users.UpdatePassword, 
                      dbo.vw_Users.Authorised, dbo.vwCompanyName.CompanyName
FROM         dbo.vw_Users INNER JOIN
                      dbo.vwCompanyName ON dbo.vw_Users.PortalId = dbo.vwCompanyName.PortalID AND dbo.vw_Users.UserId = dbo.vwCompanyName.UserID

 

(vw_Users is a DotNetNuke core SQL View, which joins the tables Users and UserPortals, resulting in a view with user information AND information about which portal users belong to.)

I now have a view of all user information including the company name.

 

Doing this for one profile property is not so much work, however, if there are many profile properties to include, creating a seperate view for all of them is rather tedious. Creating a user defined function (UDF) that returns a table is much less work. The UDF I created subsequently is this:

CREATE FUNCTION [dbo].[udf_UserProfileField]
    (
      @PropertyName NVARCHAR(50)
    )
RETURNS @ProfileFieldTable TABLE
    (
      PortalId INT,
      UserID INT,
      PropertyName NVARCHAR(50),
      PropertyValue NVARCHAR(3750)
    )
AS BEGIN
    INSERT  INTO @ProfileFieldTable
            SELECT  PPD.PortalID,
                    UP.UserID,
                    PPD.PropertyName,
                    UP.PropertyValue
            FROM    dbo.Users AS U
                    INNER JOIN dbo.UserProfile AS UP ON U.UserID = UP.UserID
                    INNER JOIN dbo.ProfilePropertyDefinition AS PPD ON UP.PropertyDefinitionID = PPD.PropertyDefinitionID
            WHERE   ( PPD.PropertyName = @PropertyName )
    
    RETURN 
   END

 

This UDF works essentially the same as the previously created view vwCompanyName. The function takes the parameter PropertyName. This allows us to easily use this UDF in combination with vw_Users. Just start creating a view like you would create any view in SQL Server, using SQL Server Management Studio. Start by adding the view “vw_Users”:

image 

next, add the function udf_UserProfileField (in fact, add it for as many profile fields you want to include in your view…):

image 

For this sample I added the function twice. For clarity i then changed the names of the 2 table functions to “UserCompany” and “UserCity”. Next, i added the relationships to the vw_Users view. Remember that the relationships are definined by both PortalId and UserId (So we know for sure that the profile properties we link to users are coming from the right portal!). Also, I selected the relationship option to show all records from the vw_Users view, since not every user might have values for all profile properties. This way, the view will return empty values for those users. The final view looks like this:

 

vwUsersComplete

The quickest way to repeat this result is to just copy and run the below sql statement:

CREATE VIEW [dbo].[vwUsersComplete]
AS
SELECT     U.UserId, U.PortalId, U.Username, U.FirstName, U.LastName, U.DisplayName, U.IsSuperUser, U.Email, U.AffiliateId, U.UpdatePassword, U.Authorised, 
                      UserCompany.PropertyValue AS Company, UserCity.PropertyValue AS City
FROM         dbo.udf_UserProfileField('City') AS UserCity RIGHT OUTER JOIN
                      dbo.vw_Users AS U ON UserCity.PortalId = U.PortalId AND UserCity.UserID = U.UserId LEFT OUTER JOIN
                      dbo.udf_UserProfileField('Company') AS UserCompany ON U.UserId = UserCompany.UserID AND U.PortalId = UserCompany.PortalId

As you can see the above view uses the same UDF 2 times, and that’s where the advantage is. You can now easily create views that link your users to their profile properties. The posibilities are endless, eg, you might want to use the DotNetNuke Reports module to render the results of this view to a DNN page, while using the Reports Module’s powerful rendering capabilities.

Rate this:
Recent Comments
Thanks Erik, I have been doing the old way all day today and I am soooo happy to see your post on the easy way!
Posted By: Stuart Hilbert on 04/27/2009
Great post, and great timing. I was going to have to do something like this soon with one of my open source modules.
Posted By: Will Strohl on 04/27/2009
Thanks Erik, I have been spending hours trying to get something like this.
Posted By: Antony S on 04/27/2009
Hey Erik, It was suggested that this process would be a good way to build a "Birthday Announcement" on my DNN 4.9.5 website, using our staff's DNN profiles, including their date of birth. Can you elaborate on implementing your suggestions in this manner?
Posted By: Joe LaTulippe on 10/16/2009

Powered By

DotNetNuke Powered! This site is proudly powered by DotNetNuke.

 

(Advertisements)

My other blogs

Thu, 21 May 2009 18:41:00 +0200

Fri, 01 May 2009 14:57:00 +0200

Wed, 29 Apr 2009 16:11:00 +0200

Mon, 27 Apr 2009 20:33:05 +0200

Wed, 21 Jan 2009 20:13:00 +0100

Mon, 05 Jan 2009 23:00:00 +0100

Fri, 05 Dec 2008 16:45:08 +0100

Sun, 05 Oct 2008 22:23:00 +0200

Wed, 17 Sep 2008 14:07:00 +0200

Sun, 24 Aug 2008 21:23:00 +0200