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;
                      }
               }
     }
  • 相关阅读:
    windows10 + anaconda + tensorflow-1.5.0 + python-3.6 + keras-2.2.4配置和安装
    k-center问题-学习
    交换机+路由器 网络口连接桥接关系示意
    用scp命令来通过ssh传输文件,ssh推送.py程序到CentOS7服务器端出现lost connection错误
    codevs 1519 过路费 最小生成树+倍增
    10.18 noip模拟试题
    poj 3565 ants
    [国家集训队2011]种树 (神贪心~~)
    poj 1821 Fence 单调队列优化dp
    SPFA 小优化*2
  • 原文地址:https://www.cnblogs.com/love007/p/2371803.html
Copyright © 2011-2022 走看看