I have a feature receiver with the following code:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = (SPSite)properties.Feature.Parent;
SPWeb web = site.RootWeb;
ProvisionHelper.SetContentType(web);
}
and in SetContentType:
public static void SetContentType(SPWeb web)
{
using (SPWeb storiesWeb = web.Webs[Constants.SiteNames.Stories])
{
var stories = storiesWeb.Lists.TryGetList(Constants.ListNames.Pages);
if (stories != null && stories.ContentTypes[Constants.ContentTypeNames.Story] == null)
{
SPContentType storyContentType = web.AvailableContentTypes[Constants.ContentTypeNames.Story];
if (storyContentType != null)
{
stories.ContentTypes.Add(storyContentType);
// Set the story content type to be the default one
SPContentTypeCollection currentOrder = stories.ContentTypes;
List<SPContentType> result = new List<SPContentType>();
foreach (SPContentType ct in currentOrder)
{
if (ct.Name.Contains(Constants.ContentTypeNames.Story))
result.Add(ct);
}
stories.RootFolder.UniqueContentTypeOrder = result;
try
{
storiesWeb.AllowUnsafeUpdates = true;
stories.Update();
}
finally
{
storiesWeb.AllowUnsafeUpdates = false;
}
}
}
}
}
on stories.Update()
I get the following error:
"Save Conflict.
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes."
I have tried a few things with web.Update(), web.AllowUnsafeUpdates = true
etc but first time I deploy I always get the same error, if I deploy it again I don't get any error. I'm sure it's something simple but I can't see it right now.
Any ideas?
Thanks in advance.