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
  13. 1 items are tagged with email validation
  14. 1 items are tagged with GMail
  15. 1 items are tagged with Google
  16. 1 items are tagged with Google Apps
  17. 1 items are tagged with IBaseEntity
  18. 2 items are tagged with IdentitySwitcher
  19. 1 items are tagged with IHydratable
  20. 1 items are tagged with Inline Skin Object
  21. 2 items are tagged with Installation
  22. 1 items are tagged with Installer
  23. 1 items are tagged with intellisense
  24. 1 items are tagged with IPropertyAccess
  25. 1 items are tagged with Language
  26. 1 items are tagged with Manifest
  27. 1 items are tagged with moving
  28. 1 items are tagged with OpenForce
  29. 1 items are tagged with Permissions
  30. 1 items are tagged with Profile Properties
  31. 1 items are tagged with PropertyEditorControl
  32. 1 items are tagged with recent projects
  33. 1 items are tagged with regex
  34. 1 items are tagged with Sample Module
  35. 1 items are tagged with Search Results
  36. 2 items are tagged with Skin Object
  37. 1 items are tagged with Skinning
  38. 6 items are tagged with SQL
  39. 1 items are tagged with SQL Server
  40. 1 items are tagged with SQL Server 2008
  41. 1 items are tagged with Table Functions
  42. 2 items are tagged with TellCo
  43. 1 items are tagged with TokenReplace
  44. 2 items are tagged with Too Good to be True
  45. 1 items are tagged with Twitter
  46. 2 items are tagged with UPC
  47. 2 items are tagged with Upgrading
  48. 1 items are tagged with Users
  49. 2 items are tagged with visual studio
  50. 1 items are tagged with Visual Studio 2008

My Twitter Feed...

Thu, 29 Jul 2010 16:45:45 +0200

erikvb: Gettin unhealthy food. Yummy!

Thu, 29 Jul 2010 07:06:10 +0200

erikvb: RT @mashable: Google Makes Custom Web Typography Ridiculously Easy - http://ow.ly/2i8DG

Wed, 28 Jul 2010 05:05:48 +0200

erikvb: @Alyssa_Milano cool, you have a clone AND you are followed by @wilw . I can only dream of achieving the same...

Tue, 27 Jul 2010 22:20:49 +0200

erikvb: http://bit.ly/bwCZdB (Popularity is Everything: A new approach to protecting passwords from statistical-guessing attacks)

Tue, 27 Jul 2010 16:51:58 +0200

erikvb: RT @Telerik: Win an iPad or Telerik Ultimate licenses. Contest details at http://bit.ly/99ep9O [please RT]

Tue, 27 Jul 2010 10:06:20 +0200

erikvb: RT @TimoBreumelhof: Small bugfix for Style Helper #DNN #skin object posted: http://dnnskinextensions.codeplex.com/releases/view/47234

Mon, 26 Jul 2010 18:39:00 +0200

erikvb: @jbrinkman have fun playing with it :)

Mon, 26 Jul 2010 18:34:22 +0200

erikvb: @schotman als het maar droog blijft

Mon, 26 Jul 2010 17:51:38 +0200

erikvb: RT @christoc: RT @DNNCorp Get new insights from #DotNetNuke CEO Navin Nagiah at CMS Critic: http://bit.ly/aqkKwm

Sun, 25 Jul 2010 20:35:09 +0200

erikvb: RT @Heuserkampf: This will be interesting: Facebook lets publishers contact “likers”: http://bit.ly/9orOQN

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