Search code examples
c#sharepoint-userprofile

Is it possible to read all properties configured for a user profile sync connection using c#


Is it possible to read all the fields that was set to create a user profile sync connection . So far I was only able to get the Display Name of the Connection.

Please help.

Thanks in advance.

 SPServiceContext context = SPServiceContext.GetContext(site);
 UserProfileConfigManager upcm = new UserProfileConfigManager(context);
 ConnectionManager cm = upcm.ConnectionManager;
     foreach (Connection cn in cm)
     {
         Console.WriteLine("Connection Name " + cn.DisplayName);
     }

Solution

  • I suppose you mean property instead of fields

    Yes it is possible with the use of reflection.

    foreach (Connection cn in cm)
    {
        var properties = cn.GetType()
                           .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                           .Where(i => i.CanRead)
        foreach(var property in properties)
        {
            Console.WriteLine("{0} - {1}", property.Name, property.GetValue(cn));
        }
    }