Recently we stumbled upon a task to set some properties of a personal mysite site collection of a user – we wanted to get precisly the user (owner) whose the site collection is, not the user who is browsing the sitecollection (current user) nor the user who is running a script. We found two ways of doing this.

Get the site collection owner

The easiest way is just to get the site collection owner of the personal mysite site collection. This C# code would do the job:

 

The problem would arise, if someone changes and plays with the site collection owners (seen that, been there).

Get the user from property bag of the root web

The other way of getting the user is to use an internal SharePoint’s property in the web porperty bag. It turns out that under a key, beautifully called „urn:schemas-microsoft-com:sharepoint:portal:profile:userprofile_guid” we can find the actual guid of the user:

 

Happy coding!

Tagged with:
 

Comments are closed.

Set your Twitter account name in your settings to use the TwitterBar Section.