当前位置:  开发笔记 > 编程语言 > 正文

如何计算用户MySite的ID

如何解决《如何计算用户MySite的ID》经验,为你挑选了1个好方法。

在用C#编写的Sharepoint WebPart中,我需要查找当前用户MySite的ID,或者检查当前站点是否为用户MySite.

想法?



1> Arry..:

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

在引用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

很明显,不是真的!

推荐阅读
郑小蒜9299_941611_G
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有