zoukankan      html  css  js  c++  java
  • SharePoint 2010 代码操作个人站点下的照片

    需要引用如下DLL
    image
    代码如下:
    using Microsoft.SharePoint;
    using Microsoft.Office.Server.UserProfiles;
    //设置站点图片
    using (SPSite site = new SPSite("siteUrl"))
    {
       SPServiceContext context = SPServiceContext.GetContext(site);
       UserProfileManager myUserProfileManager = new UserProfileManager(context);
    
       try
       {
          foreach (UserProfile aUser in myUserProfileManager)
          {
             string origUrl = (string)aUser[PropertyConstants.PictureUrl].Value;
             string newUrl = origUrl.Replace("http://mysite", "https://mysite");
             aUser[PropertyConstants.PictureUrl].Value = newUrl;
             aUser.Commit();
          }
       }
       catch (System.Exception ex)
       {
          Console.WriteLine(ex.Message);
       }
    }
     
    //得到个人站点下的照片
    //得到当前站点
    using (SPSite aSite = SPContext.Current.Site)
    {
             if (aSite != null)
             {
                     SPWeb web = SPContext.Current.Web;
                     if (web != null)
                      {
                           SPServiceContext context = SPServiceContext.GetContext(aSite);
                           UserProfileManager myUserProfileManager = new UserProfileManager(context);
                           string userName = web.CurrentUser.LoginName; //Environment.UserDomainName + "\\" + Environment.UserName;
                           if (!string.IsNullOrEmpty(userName))
                           {
                               //管理员为administrator必须特殊处理
                                   if (userName.ToLower() == "sharepoint\\system")
                                {
                                     userName = string.Format("{0}\\administrator",this.DomainName);
                                }
                          }
                          UserProfile currentUser = myUserProfileManager.GetUserProfile(userName);
                          string origUrl = (string)currentUser[PropertyConstants.PictureUrl].Value;
                          //如果没有照片即可设置默认值
                             this.Image_MyPhoto.ImageUrl = string.IsNullOrEmpty(origUrl) == true ? "/_layouts/Images/MySitePictureWebPart/14nophoto.png" : origUrl;
                      }
               }
     }
  • 相关阅读:
    acwing 116. 飞行员兄弟
    leetcode 1041. 困于环中的机器人
    acwing 110 防晒
    acwing 167. 木棒
    AcWing 166. 数独
    solr4.7新建core
    solr4.7新建core
    Solr4.7从文件创建索引
    Solr4.7从文件创建索引
    Solr4.7从文件创建索引
  • 原文地址:https://www.cnblogs.com/love007/p/2371803.html
Copyright © 2011-2022 走看看