Beispiel #1
0
        static void MaritalStatus()
        {
            //Code example adds a new property called Marital Status.
            using (SPSite site = new SPSite("http://servername"))
            {
                //SPServiceContext context = SPServiceContext.GetContext(site);
                //ClientContext context = new ClientContext(site);
                //ServerContext context = ServerContext.GetContext(site);
                UserProfileConfigManager upcm = new UserProfileConfigManager();

                try
                {
                    ProfilePropertyManager ppm = upcm.ProfilePropertyManager;

                    // create core property
                    CorePropertyManager cpm = ppm.GetCoreProperties();
                    CoreProperty        cp  = cpm.Create(false);
                    cp.Name        = "MaritalStatus";
                    cp.DisplayName = "Marital Status";
                    cp.Type        = PropertyDataType.StringSingleValue;
                    cp.Length      = 100;

                    cpm.Add(cp);

                    // create profile type property
                    ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
                    ProfileTypeProperty        ptp  = ptpm.Create(cp);

                    ptpm.Add(ptp);

                    // create profile subtype property
                    ProfileSubtypeManager         psm  = ProfileSubtypeManager.Get();
                    ProfileSubtype                ps   = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                    ProfileSubtypePropertyManager pspm = ps.Properties;
                    ProfileSubtypeProperty        psp  = pspm.Create(ptp);

                    psp.PrivacyPolicy  = PrivacyPolicy.OptIn;
                    psp.DefaultPrivacy = Privacy.Organization;

                    pspm.Add(psp);
                }
                catch (DuplicateEntryException e)
                {
                    Console.WriteLine(e.Message);
                    Console.Read();
                }
                catch (System.Exception e2)
                {
                    Console.WriteLine(e2.Message);
                    Console.Read();
                }
            }
        }
Beispiel #2
0
 public UserProfilePropertyDescriptor(ProfileSubtypeProperty propery)
     : base(propery.Name, new Attribute[] { new DisplayNameAttribute(propery.DisplayName) })
 {
     Contract.Requires(propery != null);
 }
Beispiel #3
0
        /// <summary>
        ///     Get the value of all mapped user property fields
        /// </summary>
        /// <param name="prop"></param>
        /// <param name="user"></param>
        private void getUserProfilePropertyValue(ProfileSubtypeProperty prop, UserProfile user, SPWeb currentWeb)
        {
            try
            {
                switch (prop.Name)
                {
                case "AccountName":
                    if (user[prop.Name].Value != null)
                    {
                        _accountName = user[prop.Name].Value.ToString();
                    }
                    break;

                case "FirstName":
                    if (user[prop.Name].Value != null)
                    {
                        _firstName = user[prop.Name].Value.ToString();
                    }
                    break;

                case "Title":
                    if (user[prop.Name].Value != null)
                    {
                        _jobTitle = user[prop.Name].Value.ToString();
                    }
                    break;

                case "LastName":
                    if (user[prop.Name].Value != null)
                    {
                        _lastName = user[prop.Name].Value.ToString();
                    }
                    break;

                case "EmployeeID":
                    if (user[prop.Name].Value != null)
                    {
                        _employeeID = user[prop.Name].Value.ToString();
                    }
                    break;

                case "DepartmentNumber":    //TODO:- Investigate internal fieldname
                    if (user[prop.Name].Value != null)
                    {
                        _deptNum = user[prop.Name].Value.ToString();
                    }
                    break;

                case "Department":
                    if (user[prop.Name].Value != null)
                    {
                        _division = user[prop.Name].Value.ToString();
                    }
                    break;

                case "IPPhone":
                    if (user[prop.Name].Value != null)
                    {
                        _ipPhone = user[prop.Name].Value.ToString();
                    }
                    break;

                case "WorkPhone":
                    if (user[prop.Name].Value != null)
                    {
                        _workPhone = user[prop.Name].Value.ToString();
                    }
                    break;

                case "WorkEmail":
                    if (user[prop.Name].Value != null)
                    {
                        _email = user[prop.Name].Value.ToString();
                    }
                    break;

                case "Manager":
                    if (user[prop.Name].Value != null)
                    {
                        _manager = user[prop.Name].Value.ToString();
                    }
                    break;

                case "CompanyName":     //TODO:- Find internal field name
                    if (user[prop.Name].Value != null)
                    {
                        _companyName = user[prop.Name].Value.ToString();
                    }
                    break;

                case "Office":
                    if (user[prop.Name].Value != null)
                    {
                        _officeAddress = user[prop.Name].Value.ToString();
                    }
                    break;

                case "StartDate":
                    if (user[prop.Name].Value != null)
                    {
                        _startDate = ConvertToDateTime(user[prop.Name].Value.ToString());
                    }
                    break;

                default:
                    upFieldName.Add(prop.Name);
                    //upFieldValue.Add(user[prop.Name].Value.ToString()); //TODO: handle multi-values
                    upFieldValue.Add("");
                    break;
                }
            }
            catch (Exception err)
            {
                LogErrorHelper objErr = new LogErrorHelper(LIST_SETTING_NAME, currentWeb);
                objErr.logSysErrorEmail(APP_NAME, err, "Error at getUserProfilePropertyValue function");
                objErr = null;

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