Exemplo n.º 1
0
 /// <summary>
 /// Set a given property for a given user to the passed value (simple type)
 /// </summary>
 /// <typeparam name="T">Type of the passed property value</typeparam>
 /// <param name="property">Name of the property to update</param>
 /// <param name="propertyValue">Property value of type T</param>
 /// <param name="user">Login name of the user profile to update</param>
 public void SetPropertyForUser <T>(string property, T propertyValue, string user)
 {
     UserProfileASMX.PropertyData[] newdata = new UserProfileASMX.PropertyData[1];
     newdata[0]                 = new UserProfileASMX.PropertyData();
     newdata[0].Name            = property;
     newdata[0].Values          = new ValueData[1];
     newdata[0].Values[0]       = new ValueData();
     newdata[0].Values[0].Value = propertyValue;
     newdata[0].IsValueChanged  = true;
     ups.ModifyUserPropertyByAccountName(user, newdata);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the value (simple type) of a given property for a given user
        /// </summary>
        /// <param name="property">Name of the property</param>
        /// <param name="user">Login name of the user profile to read</param>
        /// <returns>The value of the returned property</returns>
        public T GetPropertyForUser <T>(string property, string user)
        {
            UserProfileASMX.PropertyData p = UPS.GetUserPropertyByAccountName(user, property);

            if (p.Values.Length > 0)
            {
                return((T)p.Values[0].Value);
            }
            else
            {
                return(default(T));
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            UserProfileManager upm = new UserProfileManager();

            // Office 365 Multi-tenant sample
            upm.User           = "******";
            upm.Password       = GetPassWord();
            upm.TenantAdminUrl = "https://bertonline-admin.sharepoint.com";
            string userLoginName = "i:0#.f|membership|[email protected]";

            // On-premises or Office 365 Dedicated sample
            //string userLoginName = @"SET1\KevinC";
            //upm.User = "******";
            //upm.Password = GetPassWord();
            //upm.Domain = "SET1";
            //upm.MySiteHost = "https://sp2013-my.set1.bertonline.info";

            Console.Write(String.Format("Value of {0} for {1} :", "AboutMe", userLoginName));
            Console.WriteLine(upm.GetPropertyForUser <String>("AboutMe", userLoginName));
            Console.WriteLine("-----------------------------------------------------");
            Console.WriteLine("");
            Console.Write(String.Format("Value of {0} for {1} :", "SPS-LastKeywordAdded", userLoginName));
            Console.WriteLine((upm.GetPropertyForUser <DateTime>("SPS-LastKeywordAdded", userLoginName)).ToLongDateString());
            Console.WriteLine("-----------------------------------------------------");
            Console.WriteLine("");
            Console.WriteLine(String.Format("Set value of {0} for {1} to {2}:", "AboutMe", userLoginName, "I love using Office AMS!"));
            upm.SetPropertyForUser <String>("AboutMe", "I love using Office AMS!", userLoginName);
            Console.WriteLine("");
            Console.Write(String.Format("Value of {0} for {1} :", "AboutMe", userLoginName));
            Console.WriteLine(upm.GetPropertyForUser <String>("AboutMe", userLoginName));
            Console.WriteLine("-----------------------------------------------------");
            Console.WriteLine("");
            //nl-BE,fr-BE,en-US,de-DE
            Console.Write(String.Format("Value of {0} for {1} :", "SPS-MUILanguages", userLoginName));
            UserProfileASMX.PropertyData p = upm.GetPropertyForUser("SPS-MUILanguages", userLoginName);
            Console.WriteLine(p.Values[0].Value.ToString());
            Console.WriteLine("");
            Console.WriteLine(String.Format("Set value of {0} for {1} to {2}:", "SPS-MUILanguages", userLoginName, "nl-BE,en-US"));
            UserProfileASMX.PropertyData[] pMui = new UserProfileASMX.PropertyData[1];
            pMui[0]                 = new UserProfileASMX.PropertyData();
            pMui[0].Name            = "SPS-MUILanguages";
            pMui[0].Values          = new UserProfileASMX.ValueData[1];
            pMui[0].Values[0]       = new UserProfileASMX.ValueData();
            pMui[0].Values[0].Value = "nl-BE,en-US";
            pMui[0].IsValueChanged  = true;
            upm.SetPropertyForUser("SPS-MUILanguages", pMui, userLoginName);
            Console.WriteLine("-----------------------------------------------------");
            Console.WriteLine("");

            Console.ReadLine();
        }