• sharepoint2010 UserProfileManager使用注意事项22


    • class Program  
    •   
    •  {  
    •   
    •      static void Main(string[] args)  
    •   
    •      {  
    •   
    •          try  
    •   
    •          {  
    •   
    •              using (SPSite site = new SPSite("http://ianzhang/"))  
    •   
    •              {  
    •   
    •   
    •   
    •                  ServerContext context = ServerContext.GetContext(site);  
    •   
    •                  UserProfileManager profileManager = new UserProfileManager(context);  
    •   
    •                  if (profileManager.UserExists(site.OpenWeb().CurrentUser.LoginName))  
    •   
    •                  {  
    •   
    •                      UserProfile user1 = profileManager.GetUserProfile(@"ianzhang/administrator");  
    •   
    •                      Console.WriteLine("Profile {0}", user1.MultiloginAccounts[0]);  
    •   
    •                      foreach (Property prop in profileManager.Properties)  
    •   
    •                      {  
    •   
    •                          Console.WriteLine("/t{0} : {1}", prop.DisplayName, RenderProperty(user1, prop));  
    •   
    •                      }  
    •   
    •                  }  
    •   
    •              }  
    •   
    •          }  
    •   
    •          catch (Exception ex)  
    •   
    •          {  
    •   
    •              Console.WriteLine(ex.Message);  
    •   
    •          }  
    •   
    •   
    •   
    •          Console.ReadLine();  
    •   
    •      }  
    •   
    •   
    •   
    •      static string RenderProperty(UserProfile profile, Property prop)  
    •   
    •      {  
    •   
    •          UserProfileValueCollection values = profile[prop.Name];  
    •   
    •          if (values.Value == null)  
    •   
    •              return "(NULL)";  
    •   
    •   
    •   
    •          if (prop.IsMultivalued)  
    •   
    •          {  
    •   
    •              StringBuilder sb = new StringBuilder();  
    •   
    •              foreach (object o in values)  
    •   
    •              {  
    •   
    •                  sb.AppendFormat("{0} ", o);  
    •   
    •              }  
    •   
    •   
    •   
    •              return sb.ToString();  
    •   
    •          }  
    •   
    •          else  
    •   
    •          {  
    •   
    •              return values.ToString();  
    •   
    •          }  
    •   
    •      } 
  • 相关阅读:
    IntelliJ IDEA 2020.1.1中java web项目的配置
    Js查漏补缺10-数组、栈、队列、回调函数等
    Js查漏补缺09-this对象
    Js查漏补缺08-闭包
    Js查漏补缺07-匿名函数应用到的框架
    Js查漏补缺06-匿名函数的用法
    Js查漏补缺05-函数
    Js查漏补缺04-Object类型
    Js查漏补缺03-循环结构
    Runnabler
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/2932819.html
Copyright © 2020-2023  润新知