サイト コレクション内のすべてのユーザー プロファイルの PictureUrl プロパティを変更する
最終更新日: 2010年5月28日
適用対象: SharePoint Server 2010
このトピックのコード サンプルでは、サイト コレクション内のすべてのユーザーの PictureUrl プロパティの値を変更して、その値がユーザー プロファイル写真の新しい場所または URL に一致するようにします。
コードを使用した、すべてのユーザーの PictureUrl プロパティの変更
個人用サイト Web サイトのホストを別の場所に移動するときは、ほとんどの場合個人サイトの写真も移動します。写真の場所を移動した場合は、サイト コレクション内のすべての UserProfile オブジェクトの PictureUrl プロパティを変更して、新しい場所に一致するようにする必要があります。この作業は、新しい場所の URL が前の URL と異なる場合、または、Secure Socket Layer (SSL) の使用を開始し、このプロトコルに準拠するための画像 URL を変更する必要がある (つまり、http:// ではなく、https:// で始める必要がある) 場合に必要です。次のコード サンプルでは、サイト コレクション内のすべての UserProfile オブジェクトの PictureUrl プロパティを変更する方法を示します。サイト コレクションは、個人用サイトのホストに相当します。ここでは、Microsoft .NET Framework 3.5 上に構築していて、Microsoft Visual Studio 2010 プロジェクトに次の参照を追加していることを前提とします。
Microsoft.SharePoint
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);
}
}
関連項目
参照
Microsoft.Office.Server.UserProfiles