Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

A few custom properties have been added to the user object via CA. I would I retrieve these fields programmatically?

Solution:

     UserProfileManager mgr = new UserProfileManager(SpServiceContext.current);
     UserProfile user = mgr.GetUserProfile(bool);
     String str = (string)user["fields"].Value;
share|improve this question
    
I think you should change the title, because it's not the SPUser class that you were interested in, in the first place. –  Norbert Dec 12 '12 at 16:26
    
Will do, but it is the information of the spuser I wanter but I believe I still get the values using the userprofile/userprofile manager –  user13186 Dec 12 '12 at 16:43
add comment

2 Answers

up vote 0 down vote accepted

I presume your talking about the code below?

SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPUser oUser = oWebsite.AllUsers["User_Name"];

    string E-mail_Address = oUser.Email;
    string Display_Name = oUser.Name;
    string User_Notes = oUser.Notes;


    string cutomProp = oUser.CustomeMade;

}

did you add to Microsoft.SharePoint.SPUser? if you have, build save the Microsoft.SharePoint.SPUser. In your project add reference to the new dll (navigate to the folder and goto the bin folder with the updates).

You should now see your changes in the project ;)...... that is if it what your looking for ;)

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.aspx

hope it helps :)

share|improve this answer
add comment

You retrieve and set the custom properties the same as any other attribute in the profile property bag.

Here is a powershell script written to import CSV into the User Properties, works for standard and custom fields:

http://iedaddy.com/2010/06/sharepoint-2010-updating-user-profile-properties-with-powershell/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.