0

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.

1 Answer 1

0

Try changing your using statement to:

using (SPWeb storiesWeb = new SPSite(site.Webs[Constants.SiteNames.Stories].Url).OpenWeb())) {...}

Also try calling update just after adding the content type. Then REFETCH the 'stories' list and do your modifications and then call update again. I've had a similar problem when updating content types via powershell which involved getting the content type each time again otherwise I'd get the save conflict issues.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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