Skip to main content
2 of 2
added 118 characters in body
Ali Jafer
  • 17.8k
  • 1
  • 28
  • 41

can you try this:

using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID)) 

instead of:

using (SPWeb web = site.OpenWeb()) 

this will explain why your code is failing :)

http://blogs.msdn.com/b/sasohail/archive/2010/10/31/access-denied-within-spsecurity-runwithelevatedprivileges.aspx

another method is to use this:

http://sarangasl.blogspot.co.uk/2009/12/add-user-to-sharepoint-user-group.html

hope it helps :)

Ali Jafer
  • 17.8k
  • 1
  • 28
  • 41