We are using SharePoint Foundation 2010. We are creating content database and site collection using server object model. We have more than 1000 users in SharePoint. As content database and site collection creation are administartive task, only farm administartor can do that. In our case any user should be able to create content database and site collection with farm administartor account. Can we use SPUser or Is there any other way to do this ? Can you please provide me any code or link through which I can resolve the above issue ?
Asked
Active
Viewed 891 times
1 Answers
2
It sounds like you might need to use the SPSecurity.RunWithElevatedPrivleges. This will allow you to run the code as if you were the farm administrator the application pool identity account. Be careful because it gives the user running the code full higher access, but it sounds like that is what you want.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite topSite = new SPSite("URL_OF_YOUR_SITE_COLLECTION"))
{
//Any code you run here would run with the permissions of the application pool identity
}
});

Peter Jacoby
- 2,406
- 25
- 26
-
5This is factually wrong - RunWithElevatedPrivileges runs the code as the Application Pool Identity, which is is not the Farm Administator (unless your code is running within Central Administration). – James Love Feb 20 '14 at 13:17
-
You're right, I've edited the post with your corrections, thanks for pointing that out. – Peter Jacoby Feb 20 '14 at 20:33
-
@PeterJacoby You should probably correct the code comment , too :) – Ole Albers Sep 15 '14 at 12:17
-
And that's fixed now too :) – Peter Jacoby Sep 16 '14 at 19:10