In the following method, 'list' is simply an SPList ("Documents"). I'm attempting to add ContentTypes to the list and then update it. This code is found in the FeatureActivated event of an event receiver.

   list.ContentTypesEnabled = true;

    foreach (var contentTypeName in DocumentCTNames)
        SPContentType ct = web.Site.RootWeb.ContentTypes[contentTypeName];

        if (ct != null && list.ContentTypes[ct.Name] == null)


The line list.ContentTypes.Add(ct) gives me 2 inner exceptions:

"Make sure you have sufficient privileges to access this resource..."


"If you are attempting to access a file make sure it is not readonly..."

What I've tried:

  • Running with elevated priveleges (still same exception)
  • 1
    Just to be on the safe side, can you post the full code of the run with elevated privileges version? Also, can you specify which user you are using to activate the feature? Are you activating it from the web interface or comand line (for example in powershell)? – BlueSoul Sep 26 '12 at 12:27
  • @SPArchaeologist - thanks for your reply. I'll get the EleveatedPrivileges code copied across asap and put into the OP. The site is created from the code-behind of an application page. The user, in this particular instance, is the System Account. I'm the site collection admin - I suppose, on reflection, this code shouldn't be without RunWithElevatedPrivileges obviously as not all users will be admin. – JᴀʏMᴇᴇ Sep 26 '12 at 12:39
  • Cracked it, I'll post my answer shortly for those landing on this page with a similar issue. Thanks for your response @SPArchaeologist – JᴀʏMᴇᴇ Sep 26 '12 at 12:49
  • what was your solution deemac? – user11576 Oct 24 '12 at 13:54

Make sure to re-open a new SPSite inside the SPSecurity.RunWithElevatedPrivileges in order to run as the administrator.

  • Thanks a lot for your reply! I'm aware of this from coming across RunWithElevatedPrivileges not actually running with elevated privileges in a previous project - so my using statements are all in order, lessons learnt this time - I'll update the OP in a moment with my RunWithElevatedPrivileges 'version' of this code. Thanks again. – JᴀʏMᴇᴇ Sep 26 '12 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.