SubPointSolutions / spmeta2

SharePoint artifact provision for .NET platform. Supports SharePoint Online, SharePoint 2019, 2016 and 2013 via CSOM/SSOM.
http://subpointsolutions.com/spmeta2
134 stars 56 forks source link

Adding File to SitePage Lib using AddModuleFile - Save Conflict Error #1056

Open MaximilianBerg opened 7 years ago

MaximilianBerg commented 7 years ago

Hi,

I was trying to add an aspx file to the SitePages library on a SP 2016 Site. Every time i was activating the SharePoint feature, which should add the file to the library, i got a save conflict error. So I built a custom solution, whose only task was to provide this file. I activated the feature on a new, empty and english sitecollection.

After I got the error message, I checked the site and the library AND the file are available. Nevertheless I got this error the feature activation failed.

I'm using the SPMeta2 Core and SSOM Foundation Version: 1.2.130 with the following Code.

var ssomProvisionService = new SSOMProvisionService();
var currentSite = (SPSite)properties.Feature.Parent;
Homepage.Content = Resource.Homepage;

var gobSiteModel = SPMeta2Model.NewSiteModel(site =>
    site
        .AddSiteFeature(BuiltInSiteFeatures.SharePointServerPublishingInfrastructure.Enable())
);

ssomProvisionService.DeploySiteModelIncrementally(currentSite, gobSiteModel, nameof(gobSiteModel));

var gobWebModel = SPMeta2Model.NewWebModel(web =>
    web
        .AddList(BuiltInListDefinitions.SitePages, list =>
                list.AddModuleFile(Homepage)
        )
);

ssomProvisionService.DeployWebModelIncrementally(currentSite.RootWeb, gobWebModel, nameof(gobWebModel));

ModuleFileDefinition Homepage = new ModuleFileDefinition
{
    FileName = "Homepage.aspx",
    Overwrite = true,
};

Thanks.

Greeting Max

SubPointSupport commented 7 years ago

Alright, let us check this one on SharePoint 2013/2016.

SubPointSupport commented 7 years ago

Every time i was activating the SharePoint feature, which should add the file to the library, i got a save conflict error. Could you please share your exception? Is it an exception on page creation/saving or exception on SPWeb.Update() method call?

Here is what we think is happening: within a feature activation event the code tries to do several things:

All these things are already happening within feature activation event. During the current feature activation, enabling SharePointServerPublishingInfrastructure feature would trigger another SPWeb update methods, then comes back to the original feature activation, creates artefacts and .DeployWebModelIncrementally() calls another SPWeb.Update() method while saving the model state.

What we aren't sure is that where exactly the issue is happening:

To solve this, a few things can be recommended:

Let us know how it goes and if there is anything else we can help you with. We'll keep this issue open until we find a solution together.

SubPointSupport commented 7 years ago

cc @MaximilianBerg

MaximilianBerg commented 7 years ago

Hi,

thanks for the response.

I will give it a try and let you know about the results.

Greetings Max

SubPointSupport commented 7 years ago

Nice! Looking forward to hearing from you soon.