如何更改网站内容(VisualStudio主题中的代码示例演示如何在网站集中更改)
优采云 发布时间: 2021-11-28 01:07如何更改网站内容(VisualStudio主题中的代码示例演示如何在网站集中更改)
如何:更改网站集中所有用户配置文件的PictureUrl 属性。本文内容
最后修改时间:2010 年 5 月 28 日
适用范围:SharePoint Server 2010
本主题中的代码示例演示了如何更改 网站 集中每个用户的 PictureUrl 属性的值,使该值与用户*敏*感*词*照片的新位置或 URL 相对应。
使用代码修改所有用户的PictureUrl属性
当您将“我的网站”网站 主机从一个位置移动到另一个位置时,您可能希望同时移动“我的网站”照片的位置。如果移动照片的位置,则必须更改 网站 集中每个 UserProfile 对象的 PictureUrl 属性,使其对应于新位置。当新位置的 URL 与之前的 URL 不同时,或者当您开始使用安全套接字层 (SSL) 协议时,您必须更改您的图像 URL 以使其符合此协议的要求(URL 以),这种改变是必要的。下面的代码示例演示如何更改 网站 集中每个 UserProfile 对象的 PictureUrl 属性。 网站 集合应该对应于“My网站”的主机。本主题假设您在 Microsoft .NET Framework 3.5 上构建,并且您已添加以下对 Microsoft Visual Studio 2010 项目的引用:
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);
}
}
查看报价
Microsoft.Office.Server.UserProfiles
概念
SharePoint Server 2010 中的用户配置文件和社交数据
主题