Wednesday, April 20, 2011

Moss: Old content on destination farm after Content Deployment..

I'm currently working on a website which is based upon SharePoint 2007 Moss which had an issues with some specific Publishing pages not having the right content in fields after Content Deployment. The symptom was that the content of a page was modified by the contenteditor, but after a Full Content Deployment to another farm the page did not have the changes but had the old content (in Version History: v1.0).

After much searching i noticed in SharePoint Manager 2007 that some properties of the listitem were duplicated (the only difference was the names were Xml-escaped). On a page i found the properties "Basis tekst" and "Basis_x0020_tekst". On a newly created page the (escaped named) property "Basis_x0020_tekst" would not be added to the listitem.

I'm not quite sure how this duplication was introduced, but it might have something to do with that the pages were privisioned via Feature Stapling and "SimplePublishing set to False" of the web. Apparently Content Deployment overwrites the "Basis tekst" value in the destination farm with the "Basis_x0020_tekst" value. The "Basis_x0020_tekst" property still had the content at the time of provisioning.

I whipped together a simple tool to check and remove properties which had a name which after "XmlConvert.DecodeName" was already present.

private void CheckListItem(SPListItem listitem, bool fix)
{
foreach (string propertykey in listitem.Properties.Keys)
{
string decodedname = XmlConvert.DecodeName(propertykey);
if (!decodedname.Equals(propertykey) && listitem.Properties.ContainsKey(decodedname))
{
string url = SPUrlUtility.CombineUrl(listitem.Web.ServerRelativeUrl, listitem.Url);
Console.WriteLine(string.Format("Corrupt property found with name \"{0}\" on listitem \"{1}\"", propertykey, url ));
if (fix)
{
listitem.Properties.Remove(propertykey);
listitem.SystemUpdate(false);
Console.WriteLine(string.Format("Fixed by removing property \"{0}\"", propertykey));
}
}
}
}

Ofcourse this never would have occured if the fieldnames would not have had spaces in the name.