Sunday, June 2, 2013

Access User profile in Sandbox solution

This post is all about accessing user profile in SharePoint sandbox solution. First let me highlight that you cannot access user profile in sandbox solution because SPUserProfileManager is not allowed to be used inside the sandbox solution.

If you try to use it you will get the build error. So no luck in that front. So question is how do you access user profile? Well, there are people mentioning something about site user information list approach.

So what is this user information list. So it is said that the user information list is the replica of user profile. That means you can access the properties of user and its values using this list.

When the web gets created, the information gets copied from the user profile and then populated to the user information list.

Now the question comes in do you get all the properties and all the values properly for all users? Well to be honest, answer is NO. This is very disappointing.

I have no idea what is the problem with this list. It just does not work. You may find people telling that the user profile synchronization service keeps running and keeps this list updated all the time when the properties or values are updated in user profile. But this does not happen in real.

It's a big disappointing. Especially when you are dealing with developing solutions in cloud (Office 365) and when you are working tenant environment or even you have dedicated plan in office but you simple cannot run anything on the server like PowerShell.

So here is what I encountered. If you add property in user profile and then try to access this list. 

You do not get this field at all in the user information list. Come back to central administration ( If you are trying this while in development - forget about this if you are working for Office 365 / SharePoint online solutions). Run all possible timer jobs possible for user profile and you will again run out of luck.

I just don't know how this things have been configured. 

When on user profile property, it is clearly written that check the box which says replicable and do other settings. Doing that also does not help. I have tried this on five different environment and it has failed in all five environment. so it's completely not working at all.

It will work only when you forcefully apply two STSADM command. Yes, its STSADM.
When the timer job updates the site collections with the profile properties, it maintains the sync details in a table

Stsadm.exe –o sync –listolddatabases 0

and then

Stsadm.exe –o sync –deleteolddatabases 0

After executing these two commands, go ahead and again run the timer job. After this if you access the list and items, you get the new property as field with values for users.

What is the point of having a solution like this? This just does not work out. I think we all are out of luck accessing user profile in sandbox solution specially if you are dealing with SharePoint online or office 365.

Another option can be accessing the web service to access data of user profile. But you again cannot call web service in SandBox solution. So again we run out of luck.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to