Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:04:55+00:00 2026-06-12T17:04:55+00:00

I am try to replicate the following c# code using reflection: UserProfileManager userProfileManager =

  • 0

I am try to replicate the following c# code using reflection:

UserProfileManager userProfileManager = new UserProfileManager(ServerContextGoesHere);
UserProfile userProfile = null;

userProfile = userProfileManager.GetUserProfile(@"somedomain\someuser");

userProfile["PictureUrl"].Value = "This is where I want to update the value using reflection!";

userProfile.Commit();

Using reflection I can get everything to work except for the line where I’m trying to set the “PictureUrl” indexed property on the UserProfile object. That indexed property looks like this when using a decompiler:

public UserProfileValueCollection this[string strPropName]

And here is my code using reflection to achieve the same thing as the above, notice the TODO comment where I need to set the value of the PictureUrl indexed property:

   Assembly userProfileAssembly;

    var windowsFolderPath = Environment.GetEnvironmentVariable("windir");
    var pathToServerAssembly = string.Format(@"{0}\assembly\GAC_MSIL\Microsoft.Office.Server.UserProfiles\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Server.UserProfiles.dll", windowsFolderPath);

    try
    {
        userProfileAssembly = Assembly.LoadFrom(pathToServerAssembly);
    }
    catch (FileNotFoundException)
    {
        // Assembly wasn't found, so eject.
        return;
    }

    var userProfileManagerClass = userProfileAssembly.GetType("Microsoft.Office.Server.UserProfiles.UserProfileManager");
    if (userProfileManagerClass == null) return;

    var userExistsMethod = userProfileManagerClass.GetMethod("UserExists");
    if (userExistsMethod == null) return;

    var getUserProfileMethod = userProfileManagerClass.GetMethod("GetUserProfile", new[]{typeof(string)});
    if (getUserProfileMethod == null) return;

    var instantiatedUserProfileManagerClass = Activator.CreateInstance(userProfileManagerClass);
    var result = (bool)userExistsMethod.Invoke(instantiatedUserProfileManagerClass, new object[] { SPContext.Current.Web.CurrentUser.LoginName });

    if (!result) return;

    var userProfileClass = userProfileAssembly.GetType("Microsoft.Office.Server.UserProfiles.UserProfile");
    var userProfile = getUserProfileMethod.Invoke(instantiatedUserProfileManagerClass, new object[] { SPContext.Current.Web.CurrentUser.LoginName });

    //userProfile["PictureUrl"].Value = userPictureUrl;
    //TODO: HOW DO I SET THE PICTUREURL PROPERTY USING REFLECTION?

    var commitMethod = userProfileClass.GetMethod("Commit");
    commitMethod.Invoke(userProfile, null);

Thanks in advance,

Ryan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:04:56+00:00Added an answer on June 12, 2026 at 5:04 pm

    Assuming you only have one indexer on UserProfile:

    PropertyInfo indexProperty = typeof(UserProfile)
        .GetProperties()
        .Single(p => p.GetIndexParameters().Length == 1 && p.GetIndexParameters()[0].ParameterType == typeof(string));
    

    You can now get the value for the indexer and set its Value property:

    object collection = indexProperty.GetValue(userProfile, new object[] { "PictureUrl" });
    
    PropertyInfo valueProperty = collection.GetType().GetProperty("Value");
    valueProperty.SetValue(collection, userPictureUrl, null);
    

    If you have more than one matching index property you can find it with:

    PropertyInfo indexProperty = (from p in t.GetProperties()
                                  let indexParams = p.GetIndexParameters()
                                  where indexParams.Length == 1 && indexParams[0].ParameterType == typeof(string)
                                  select p).Single();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am searching LDAP using the following code in C# to poll active directory
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++) { JSONObject json_data = jArray.getJSONObject(i);
Try executing the following in JavaScript: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals
Try to see which cast is faster (not necessary better): new c++ case or
I'm getting a nullpointer exception in the following code in my application : @Override
Problem Description: Occassionally when debugging, I get the following error. I'm using visual studio
I am getting an IndexOutOfRange exception on the following line of code: var searchLastCriteria
The following code will only let me drag and drop ONE clone onto a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.