I need to get user name (first and last name) for the given login name (MyDomain\TestUser). EnsureUser does that:
SPUser responsiblePerson = web.EnsureUser (loginName);
string userName = responsiblePerson.Name;
I am not sure if that is the rigth way of getting user name, because as far as I understand it adds a user to the internal user list and the collection of users.
This is probably why it fails in sandbox solution with dreadful exception below. It does not fail in all cases, though.
Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.
Server stack trace: at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.UpdateMembers(String bstrUrl, UInt32 dwObjectType, String bstrObjId, Guid& pguidScopeId, Int32 lGroupID, Int32 lGroupOwnerId,
Object& pvarArrayAdd, Object& pvarArrayAddIds, Object& pvarArrayLoginsRemove, Object& pvarArrayIdsRemove, Boolean bRemoveFromCurrentScopeOnly, Boolean bSendEmail) at Microsoft.SharePoint.SPUserCollection.UpdateMembers(Object objUpdateInfo,
Object objAddIds, Object objRemoveLogins, Object objRemoveIds, Boolean fSendEmail) at Microsoft.SharePoin
View Complete Post