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!
source
share