Example #1
0
        /// <summary>
        ///     Update a particular user profile property field
        /// </summary>
        /// <param name="acctName"></param>
        /// <param name="fieldName"></param>
        /// <param name="fieldValue"></param>
        public void updateProfileDetails(string acctName, string fieldName, string fieldValue, SPWeb currentWeb)
        {
            try
            {
                SPSite             site                  = SPContext.Current.Site;
                SPServiceContext   ospServerContext      = SPServiceContext.GetContext(site);
                UserProfileManager ospUserProfileManager = new UserProfileManager(ospServerContext);

                UserProfile ospUserProfile = ospUserProfileManager.GetUserProfile(acctName);
                Microsoft.Office.Server.UserProfiles.PropertyCollection propColl = ospUserProfile.ProfileManager.PropertiesWithSection;

                if (ospUserProfile != null && propColl != null)
                {
                    foreach (Property prop in propColl)
                    {
                        if (fieldName == prop.Name)
                        {
                            ospUserProfile[prop.Name].Value = fieldValue;
                        }
                    }
                    ospUserProfile.Commit();
                }
            }
            catch (Exception err)
            {
                LogErrorHelper objErr = new LogErrorHelper(LIST_SETTING_NAME, currentWeb);
                objErr.logSysErrorEmail(APP_NAME, err, "Error at getUserProfileDetails function");
                objErr = null;

                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, err.Message.ToString(), err.StackTrace);
            }
        }
Example #2
0
        private bool getUserProfileDetailsById_BUG(long byUserID, SPWeb currentWeb, SPSite site)
        {
            try
            {
                //SPSite site = SPContext.Current.Site;
                SPServiceContext   ospServerContext      = SPServiceContext.GetContext(site);
                UserProfileManager ospUserProfileManager = new UserProfileManager(ospServerContext);

                UserProfile ospUserProfile = ospUserProfileManager.GetUserProfile(byUserID);
                Microsoft.Office.Server.UserProfiles.PropertyCollection propColl = ospUserProfile.ProfileManager.PropertiesWithSection;

                if (ospUserProfile != null && propColl != null)
                {
                    upFieldName  = new List <string>();
                    upFieldValue = new List <string>();

                    //Search through all user profile property fields
                    foreach (Property prop in propColl)
                    {
                        //Console.WriteLine("property Name : " + prop.Name);
                        //Console.WriteLine("proerpty Value : " + ospUserProfile[prop.Name].Value);
                        UserProfileValueCollection proValCol = ospUserProfile[prop.Name];
                        mapUserProfilePropertyValue(proValCol, prop, prop.Name, ospUserProfile[prop.Name].Value.ToString());
                    }

                    //Send email with any user profile fields not map to a custom list
                    reportUnManagedUserProfileProperties(currentWeb);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception err)
            {
                LogErrorHelper objErr = new LogErrorHelper(LIST_SETTING_NAME, currentWeb);
                objErr.logSysErrorEmail(APP_NAME, err, "Error at getUserProfileDetailsById function");
                objErr = null;

                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, err.Message.ToString(), err.StackTrace);

                return(false);
            }
        }