2

After unsetting MDS or something break permissions inheritance and update web, I am getting this error, I am creating 10 subwebs and it throws error in 5th one, I am opening new SPSite each time creating a new subweb,

Code

using (SPSite siteCol = new SPSite(siteURL))
using (SPWeb web = siteCol.OpenWeb())
{
        SPWebTemplate template = GetTemplateFromWeb(web, sTemplate);
        using (SPWeb newWeb = web.Webs.Add(shortURL, sTitle, string.Empty, web.Language, template, false, false))
        {
            AddPropertyToWeb(newWeb, "PAGETYPE"", ""PBV");
            AddWebPartToWeb(newWeb, new sMenu(), "left");
            AddWebPartToWeb(newWeb, new sDetails(), "right");
            SetUnsetMDSFeature(newWeb);
            //BreakPermissionsInheritance(newWeb);
        }
    }

private void SetUnsetMDSFeature(SPWeb newWeb)
{
    try
    {
        newWeb.AllowUnsafeUpdates = true;
        newWeb.EnableMinimalDownload = false;
        newWeb.Update();  // Exception arises here
    }
    finally
    {
        newWeb.AllowUnsafeUpdates = false;
    }
}

Just Exception

The web being updated was changed by an external process.

Exception - Stack

at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.SetWebProps(String bstrUrl, String bstrTitle, String bstrDescription, UInt32 nLocale, UInt16 nTimeZone, Boolean bTime24, Int16 nCalendarType, Int16 nAdjustHijriDays, Int16 nAltCalendarType, Boolean bShowWeeks, Int16 nFirstWeekOfYear, Int16 nFirstDayOfWeek, Int16 nWorkDays, Int16 nWorkDayStartHour, Int16 nWorkDayEndHour, Int32 lFlags, Int32 lDontIgnoreFlagsMask, Int16 nCollation, UInt32 nAuthor, String bstrThemedCssFolderUrl, String bstrCustomizedCssFileList, String bstrAlternateCssUrl, String bstrAlternateHeaderUrl, String bstrMasterUrl, String bstrCustomMasterUrl, String bstrCustomJSUrl, String bstrSiteLogoUrl, String bstrSiteLogoDescription, Boolean bUpdateTimeCreated, DateTime dtTimeCreated, Boolean bUpdateTimeLastModified, DateTime dtTimeLastModified, Boolean bOverwriteMUICultures, Boolean bMUIEnabled, String bstrAlternateMUICultures, Int32 uiVersion, Int16 nClientTag, UInt32& nCollationLCID) at Microsoft.SharePoint.SPWeb.Update() at Deployment.WebServices.Internal.Deployment.SetUnsetMDSFeature(SPWeb newWeb) at Deployment.WebServices.Internal.Deployment.DeployDecisions(String pSchemeURL, Int32 lcid) at SyncInvokeDeployDecisions(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

Edit - ANSWER THAT WORKED FOR ME

For now because I am adding several sites and then other operations on them + SOME OTHER BUSINESS LOGIC (which takes some time), I am doing this at end by recalling all spwebs and disabling this feature.

In other Words I am using Thread.Sleep(10000), to give enough time for web provisioning.

  • Try reversing the order of MDS and breaking permissions – Nadeem Yousuf Jul 16 '15 at 8:54
  • @NadeemYousuf exception is thrown even if I remove permission inheritance method – Learner Jul 16 '15 at 8:54
3

In your code you seem to be adding a new SPWeb

 using (SPWeb newWeb = web.Webs.Add(.......))

As far as I know, the Add method is actually a non-blocking one: the method can return before the web is actually fully provisioned.

With that in mind, the issue seem to be more comprensible. Your code is trying to update the web while it is still begin provisioned. The "other process" is simply the one that is still creating the web site. If that is the case, you don't have many options. You need to wait for the provision to complete.

The SPWeb object has a Provisioned property. You may want to use that to check when the web site is ready. Also, some sources claim that simply attempting to open the web with a call to SPSite.OpenWeb after you execute the Add method will be a blocking operation and wait for the provision process to complete. You can test this option to and chose the one that seem more appropriate for your environment.

1

Try this

using (SPSite site = new SPSite(siteURL))
using (SPWeb parentWeb = site.OpenWeb())
{
    SPWebTemplate template = GetTemplateFromWeb(parentWeb, sTemplate);
    parentWeb.AllowUnsafeUpdates = true;
    SPWeb newWeb = parentWeb.Webs.Add(shortURL, sTitle, string.Empty, parentWeb.Language, template, false, false)

    try { newWeb.Update(); }

    parentWeb.AllowUnsafeUpdates = false;
    newWeb.AllowUnsafeUpdates = true;

    AddPropertyToWeb(newWeb, "PAGETYPE"", ""PBV");
    AddWebPartToWeb(newWeb, new sMenu(), "left");
    AddWebPartToWeb(newWeb, new sDetails(), "right");
    SetUnsetMDSFeature(newWeb);
    //BreakPermissionsInheritance(newWeb);

    newWeb.AllowUnsafeUpdates = false;
    newWeb.Dispose();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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