Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow do you set profile property visibility programmatically using C#?How do you set profile property visibility programmatically using C#?
Previous
 
Next
New Post
1/31/2012 6:33 PM
 

I have tried several variations of the following:

UserInfo ui = new UserInfo();
ui = UserInfo;
ui.Profile.SetProfileProperty("Email2", txtEmail2.Text); 
ui.Profile.ProfileProperties.GetByName("Email2").Visibility = UserVisibilityMode.AllUsers; 
UserController.UpdateUser(PortalId, ui); 

I have also tried ProfileController.UpdateUserProfile(ui); 

During debug if I drill down to the value it is correct but it does not change the value in the database.

It does change the value in the database if I change both the Email2 value and its visibility.

Anybody have an idea what is wrong?

 
New Post
1/31/2012 6:51 PM
 
I also just tried this with the same result. It only changes the visibility when the property value also changes.

ProfilePropertyDefinition ppd = new ProfilePropertyDefinition();
ppd = ui.Profile.ProfileProperties.GetByName("Email2");
ppd.Visibility = UserVisibilityMode.AdminOnly;
ProfileController.UpdatePropertyDefinition(ppd);
UserController.UpdateUser(PortalId, ui);
 
New Post
1/31/2012 8:03 PM
 

Rather than updating the profile property definition or the user you need to update the the user's profile using the following static method of the DotNetNuke.Entities.Profile.ProfileController:

public static void UpdateUserProfile (UserInfo user)

In addition to updating the user's profile in the database, it also forces a clearing of the user cache for the referenced user.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
2/1/2012 10:56 AM
 

Hi William,

 Thanks for replying.  I have tried that static method.  It works to update the profile property values but not the visibility ( AllUsers, MembersOnly, AdminOnly - 0,1,2 in the DB).  It does work on both the value and the visibility if they are both being changed at the same time.  But if the value remains the same and you are changing only the visibility it does not work.

 This is what I tried.

UserInfo.Profile.ProfileProperties.GetByName("Email2").Visibility = UserVisibilityMode.AllUsers; 
DotNetNuke.Entities.Profile.ProfileController.UpdateUserProfile(UserInfo);

 
New Post
2/24/2012 1:26 PM
 

Apparently setting the visibility using that method does not work.  You can update it straight in the SQL table --  I created a Linq DataContext & updated it that way.  Here is what I did to get it to work...

UserInfo ui = new UserInfo();
ui = UserInfo;

ui.Profile.SetProfileProperty("PropertyName", txtPropertyName.Text.Trim());
ui.Profile.ProfileProperties.GetByName("PropertyName").Visibility = UserVisibilityMode.AllUsers;  

LinqDataProviderDataContext dc = new LinqDataProviderDataContext();
//Loop thru and find the properties that are dirty
//if dirty then use Linq Datacontext to update the visibility property
foreach (ProfilePropertyDefinition item in ui.Profile.ProfileProperties)
{
    if (item.IsDirty)
    {     
        
        dc.ProfilePropertyVisUpdateSP(item.PropertyDefinitionId, UserId, (int)item.Visibility); //uses SP below to update

    }
}

DotNetNuke.Entities.Profile.ProfileController.UpdateUserProfile(ui);  //update the profile
UserController uc = new UserController();
uc.UpdateUser(ui); //update the user


Here is the SP:

CREATE PROCEDURE [dbo].[ProfilePropertyVisUpdateSP]
    -- Add the parameters for the stored procedure here
    @PropertyDefinitionId int,
    @UserId int,
    @Visibility int
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    UPDATE UserProfile
    SET Visibility = @Visibility
    WHERE UserID = @UserId AND  PropertyDefinitionID = @PropertyDefinitionId
END

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow do you set profile property visibility programmatically using C#?How do you set profile property visibility programmatically using C#?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out