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)
{
list.ContentTypes.Add(ct);
}
}
list.Update();
The line list.ContentTypes.Add(ct) gives me 2 inner exceptions:
"Make sure you have sufficient privileges to access this resource..."
and
"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)