Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
thanks, refetch the list was key –  John Nov 28 '12 at 22:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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