【问题标题】:How can you work out the ID of a users MySite如何计算出用户 MySite 的 ID
【发布时间】:2008-10-22 11:37:05
【问题描述】:

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

想法?

【问题讨论】:

    标签: c# .net sharepoint moss


    【解决方案1】:

    我花了一个下午的时间来解决这个问题。

    在引用 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 的 Site Collection ID (SPSite.ID):

    upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName).ID
    

    或站点 ID (SPWeb.ID) 通过:

    upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName).PersonalSite.RootWeb.ID
    

    很明显,不是真的!

    【讨论】:

    • 这比我的想法好多了:)
    猜你喜欢
    • 2020-11-29
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多