Today I had to troubleshoot SharePoint site provisioning code which misbehaved on a particular server. It is always fun if code works well on a dozen SharePoint farms and then fails on one farm.
The code is a really simple C# console app which reads an xml file and it then uses the taxonomy specified in the xml file to create a SP web.
As part of the provisioning, the code will activate a set of standard SharePoint features and then activate the custom developed features.
I used the application on many different SharePoint 2010 farms to provision over 30 sites but recently we ran the tool on a new farm and we suddenly started getting the following error when the code tries to activate the SharePoint Publishing Web feature:
Error: Provisioning did not succeed. Details: Failed to initialize some site properties for Web at Url: 'http://demo/Contoso' OriginalException: The web being updated was changed by an external process.
This is the original code – before I made changes:
Console.WriteLine("Creating a new web with title: " + webTitle);
site.AllowUnsafeUpdates = true;
SPWeb newweb = site.AllWebs.Add(webTitle, webTitle, webTitle, lcid, "STS#1", false, false);
site.AllowUnsafeUpdates = false;
Console.WriteLine("Web created. Ready to activate web features.");
if (newweb != null)
{
ActivateWebFeatures(newweb);
}
Console.WriteLine("Web created successfully");
I discovered that the SPWeb newweb = site.AllWebs.Add( call actually returns the SPWeb object before all provisioning has been completed so the next time I try to update newweb I get the error “The web being updated was changed by an external process.”
In order to solve this I fetched the new updated instance of the SPWeb, so I added the following line of code: newweb = site.OpenWeb(webTitle);
The following code works well:
Console.WriteLine("Creating a new web with title: " + webTitle);
site.AllowUnsafeUpdates = true;
SPWeb newweb = site.AllWebs.Add(webTitle, webTitle, webTitle, lcid, "STS#1", false, false);
site.AllowUnsafeUpdates = false;
Console.WriteLine("Web created. Ready to activate web features.");
newweb = site.OpenWeb(webTitle);
if (newweb != null)
{
ActivateWebFeatures(newweb);
}
Console.WriteLine("Web created successfully");
11 comments:
Before you call a new instance of the newWeb you must dispose the old instance, else it doesnt work.
newWeb.Dispose();
newweb = site.OpenWeb(webTitle);
if (newweb != null)
{
ActivateWebFeatures(newweb);
}
Actually adding a delay helped too
Thread.Sleep(3000);
Hi John,
Nice post ,thanks for sharing this information .
Sharepoint Development
This is good technical detail about SharePoint codes which works in many farms but fall on particular farm, and how author with the help of this content try to solve this problem for SharePoint developers.
Your code is leaking memory, you need to change it as with best practices, it won't going to work...
https://msdn.microsoft.com/en-us/library/aa973248(v=office.12).aspx
You will required to dispose this new web object by adding it within using (SPWeb addedWeb = web.Webs.Add(strWebUrl)) block.. and if you do add it to using block
Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
Java Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai
I ‘d mention that most of us visitors are endowed to exist in a fabulous place with very many wonderful individuals with very helpful things.
Best PHP Training Institute in Chennai|PHP Course in chennai
Best .Net Training Institute in Chennai
MCSE Training in Chennai
AI Training in Chennai
SEO Training in Chennai
Great Article
Final Year Projects in Python
Python Training in Chennai
FInal Year Project Centers in Chennai
Python Training in Chennai
Very Informative blog thank you for sharing. Keep sharing.
Best software training institute in Chennai. Make your career development the best by learning software courses.
php training institute in chennai
RPA Training in Chennai
DevOps Training in Chennai
Cloud-computing Training in Chennai
Ui-Path Training in Chennai
Blue-Prsim Training in Chennai
Azure Training in Chennai
Thanks a lot very much for the high quality and results-oriented help.
I won’t think twice to endorse your blog post to anybody who wants
and needs support about this area.
oracle certification in Chennai
asp net training in Chennai
Post a Comment