需求:
客户需要通过发送手机短信的服务, 因为通过SPUser对象模型中无法取到手机号码的字段信息,所以现考虑从共享服务中去获取该手机数据。
 
需要的DLL:
Microsoft.SharePoint.dll
Microsoft.Office.Server.dll
 
需要的命名空间:
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
 
主要代码:
 

 获取用户配置信息的值
获取用户配置信息的值
        public string GetPropertyValue(UserProfile profile, Property prop)
        {
            var value = string.Empty;
            UserProfileValueCollection values = profile[prop.Name];
            if (values.Value == null)
                return value;
            if (prop.IsMultivalued)
            {
                var sb = new StringBuilder();
                foreach (object o in values)
                {
                    sb.AppendFormat("{0} ", o);
                }
                value = sb.ToString();
            }
            else
            {
                value = values.ToString();
            }
            return value;
        } 
 

 获取用户的手机号码
获取用户的手机号码
        public string GetUserMobile(string siteUrl, string userAccount)
        {
            var value = string.Empty;
            try
            {
                using (SPSite site = new SPSite(siteUrl))
                {
                    var context = ServerContext.GetContext(site);
                    var profileManager = new UserProfileManager(context);
                    var user = profileManager.GetUserProfile(userAccount);
                    foreach (Property prop in profileManager.Properties)
                    {
                        if (prop.DisplayName == "移动电话")
                        {
                            value = GetPropertyValue(user, prop);
                        }
                    }
                }
            }
            catch { }
            return value;
        }