2

Currently created User Profile Custom Property "Function" programmatically,But I Don't Know How To assign Value To That Custom Property programmatically.

3

You do that like you would with a custom column on a list. You instantiate the UserProfileManager, and then you can either loop through each "Profile" or you can get a specific profile and set the property.

Example iterating through each:

using (var site = new SPSite("http://contoso.com")
{
    var serviceContext = SPServiceContext.GetContext(site);
    var profileManager = new UserProfileManager(serviceContext);
    var userProfiles = profileManager.GetEnumerator();

    while (userProfiles.MoveNext())
    {
        var userProfile = (UserProfile)userProfiles.Current;
        userProfile["MyCustomField"].Value = "Some value";
        userProfile.Commit(); // Might be update, can't remember.
    }
}

Example taking a single user profile and updating it:

using (var site = new SPSite("http://contoso.com")
{
    var serviceContext = SPServiceContext.GetContext(site);
    var profileManager = new UserProfileManager(serviceContext);
    var userProfile = profileManager.GetUserProfile("domain\\username");
    userProfile["MyCustomField"].Value = "Some value";
    userProfile.Commit(); // Might be update, can't remember.
}
1

You can set it for example via PowerShell (sorry, I don't know which language do you really need):

[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
Add-PSSnapin Microsoft.SharePoint.PowerShell

$site = Get-SPSite http://YourSiteCollection
$serviceContext = Get-SPServiceContext $site            

$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)
$userProfile = $upm.GetUserProfile("user@company.com");
$userProfile["Function"].Value = "Value you would like to set"   
$userProfile.Commit()

You might find this reference useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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