Thursday, October 25, 2012

Getting Sharepoint user profile values

private void GetUser(string name)
        {
           // string key = HttpContext.Current.Request.Params["id"].ToString();
           // int id = Convert.ToInt32(key);
            object user = null;

           
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(workflowProperties.SiteUrl))
                {
                     //SPUser user = SPContext.Current.Web.
                    SPServiceContext serverContext = SPServiceContext.GetContext(site);
                    UserProfileManager profileManager = new UserProfileManager(serverContext);
                   // SPUser spUser = site.RootWeb.Users.GetByID(id);
                    UserProfile profile = profileManager.GetUserProfile(name);

                    user = new
                    {
                        Account = profile["AccountName"].Value,
                        Title = profile["Title"].Value,
                        First = profile["FirstName"].Value,
                        Last = profile["LastName"].Value,
                        PreferredName = profile["PreferredName"].Value,
                        WorkPhone = profile["WorkPhone"].Value,
                        Fax = profile["Fax"].Value,
                        WorkEmail = profile["WorkEmail"].Value,
                        Office = profile["Office"].Value,
                        Manager = profile["Manager"].Value

                    };
                }
            });

           // JavaScriptSerializer ser = new JavaScriptSerializer();
           // context.Response.Write(ser.Serialize(user));
        }

No comments:

Post a Comment