在用C#编写的Sharepoint WebPart中,我需要查找当前用户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
很明显,不是真的!