When we run a piece of code within SPSecurity.RunWithElevatedPrivileges, it run in context with Sharepoint System account. So if you want to run a piece of code under a specific user account/role we have to impersonate that specific user account.
To impersonate a specific user, you need the usertoken of the impersonated user and you have to pass it while creating the SPSite object.
SPUserToken userToken = Web.SiteAdministrators["loginname"].UserToken;
using(SPSite site = new SPSite("SiteURL", userToken))
SPWeb Web = mySite.RootWeb;
// Perform activities which require administrative privileges
To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...
Recently, I stumbled upon a situation where I had Calendar list and I had provided custom save and cancel button. In List setting I had kep...
In order to call a web service in sandbox environment following steps should be followed. Note: Assuming you already have c...