How you can determine the MySite user ID

In a WebPart Sharepoint written in C #, I need to find out either the identifier of the current MySite users, or check if the current site is MySite users.

Ideas?

+3
source share
1 answer

I spent a day working on it and designed it.

Add the following statements after linking to Microsoft.Office.Server.dll and Microsoft.Sharepoint.dll

using Microsoft.SharePoint;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;

Then log in to the user profile by following these steps:

ServerContext sc = ServerContext.Current;
UserProfileManager upm = new UserProfileManager(sc);
UserProfile up = upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);

Then you can get the site identifier (SPSite.ID) of MySite through:

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

Or site identifier (SPWeb.ID) via:

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

Obvious, but not very!

+6
source

Source: https://habr.com/ru/post/1698566/


All Articles