Wednesday 30 July 2014

get user profile properties programmatically using c#

Share it Please
 public void getuserprofilesyncCustomattributesvalues(string MysitecollectionUrl)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite siteCollection = new SPSite(MysitecollectionUrl))
                {
                    using (SPWeb site = siteCollection.OpenWeb())
                    {
                        ServerContext context = ServerContext.GetContext(siteCollection);
                        UserProfileManager profileManager = new UserProfileManager(context);
                        foreach (UserProfile profile in profileManager)
                        {
                            string PersonalSiteUrl = ((string)profile["PersonalSpace"].Value);
                            string AccountName = ((string)profile["AccountName"].Value);
                        }
                    }
                }
            });

        }
 
  public void getuserprofilesyncDefaultattributesvalues(string MysitecollectionUrl)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = new SPSite(MysitecollectionUrl))
                {
                    ServerContext context = ServerContext.GetContext(site);
                    UserProfileManager profileManager = new UserProfileManager(context);
                    foreach (UserProfile profile in profileManager)
                    {
                        string Department = Convert.ToString(profile[PropertyConstants.Department].Value);
                        string AccountName = Convert.ToString((profile[PropertyConstants.AccountName].Value));
                        string Name = Convert.ToString((profile[PropertyConstants.PreferredName].Value));
                    }
                }
            });
        }
 

No comments:

Post a Comment

Followers

Follow The Author