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;
                      }
               }
     }
  • 相关阅读:
    MOSS中的User的Title, LoginName, DisplayName, SID之间的关系
    如何在Network Monitor中高亮间隔时间过长的帧?
    SharePoint服务器如果需要安装杀毒软件, 需要注意什么?
    如何查看SQL Profiler? 如何查看SQL死锁?
    什么是Telnet
    The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain.
    Windows SharePoint Service 3.0的某个Web Application无搜索结果
    网络连接不上, 有TCP错误, 如果操作系统是Windows Server 2003, 请尝试一下这里
    在WinDBG中查看内存的命令
    The virtual machine could not be started because the hypervisor is not running
  • 原文地址:https://www.cnblogs.com/love007/p/2371803.html
Copyright © 2011-2022 走看看