예제 #1
0
        private static ProfileTypeProperty EnsureProfileTypeProperty(
            CoreProperty property,
            UserProfilePropertyInfo userProfilePropertyInfo,
            ProfileTypePropertyManager profileTypePropertyManager)
        {
            var profileTypeProperty = profileTypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name);

            if (profileTypeProperty == null)
            {
                profileTypeProperty = profileTypePropertyManager.Create(property);
                profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer;
                profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor;
                profileTypeProperty.IsReplicable      = userProfilePropertyInfo.IsReplicable;
                profileTypePropertyManager.Add(profileTypeProperty);
            }
            else
            {
                profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer;
                profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor;
                profileTypeProperty.IsReplicable      = userProfilePropertyInfo.IsReplicable;
            }

            profileTypeProperty.Commit();
            return(profileTypeProperty);
        }
예제 #2
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();
                }
            }
        }
        private static ProfileTypeProperty EnsureProfileTypeProperty(
            CoreProperty property,
            UserProfilePropertyInfo userProfilePropertyInfo,
            ProfileTypePropertyManager profileTypePropertyManager)
        {
            var profileTypeProperty = profileTypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name);
            if (profileTypeProperty == null)
            {
                profileTypeProperty = profileTypePropertyManager.Create(property);
                profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer;
                profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor;
                profileTypeProperty.IsReplicable = userProfilePropertyInfo.IsReplicable;
                profileTypePropertyManager.Add(profileTypeProperty);
            }
            else
            {
                profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer;
                profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor;
                profileTypeProperty.IsReplicable = userProfilePropertyInfo.IsReplicable;
            }

            profileTypeProperty.Commit();
            return profileTypeProperty;
        }