C# 如何计算MySite用户的ID

C# 如何计算MySite用户的ID,c#,.net,sharepoint,moss,C#,.net,Sharepoint,Moss,在用c#编写的Sharepoint Web部件中,我需要找出当前用户MySite的ID,或者检查当前站点是否为用户MySite 想法?我花了一下午的时间研究这个问题,并且已经解决了 在引用Microsoft.Office.Server.dll和Microsoft.Sharepoint.dll后添加以下using语句 using Microsoft.SharePoint; using Microsoft.Office.Server; using Microsoft.Office.Server.Us

在用c#编写的Sharepoint Web部件中,我需要找出当前用户MySite的ID,或者检查当前站点是否为用户MySite


想法?

我花了一下午的时间研究这个问题,并且已经解决了

在引用Microsoft.Office.Server.dll和Microsoft.Sharepoint.dll后添加以下using语句

using Microsoft.SharePoint;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
然后通过执行以下操作访问用户配置文件:

ServerContext sc = ServerContext.Current;
UserProfileManager upm = new UserProfileManager(sc);
UserProfile up = upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
然后,您可以通过以下方式获取MySite的网站集ID(SPSite.ID):

upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName).ID
或通过以下方式获取站点ID(SPWeb.ID):


很明显,不是真的

这比我的想法好多了:)
upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName).PersonalSite.RootWeb.ID