edit part of databindings in word footer
Ondřej Čech
1
Reputation point
Hello,
As we moved some documents from on-prem to online some databindings on documents are missing
i found that it requires to update the bindings from old server to online, the difference on points ns3ns4,ns5,ns6 is
and
The code I'm using is below, but it does not change the document:
public void openLocal()
{
string document = @"C:\fakepath\AHB_00727_1.5_forCsharp.docx";
string newMapping = "xmlns:ns0='http://schemas.microsoft.com/office/2006/metadata/properties' xmlns:ns1='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns2='http://schemas.microsoft.com/office/infopath/2007/PartnerControls' xmlns:ns3='http://schemas.microsoft.com/sharepoint.v3' xmlns:ns4='97e7a30e-5f2b-44fe-86a1-0a6166467791' xmlns:ns5='7018fec8-77e8-44a6-b52a-63a974126db6' xmlns:ns6='71d29222-2c5f-45ad-9aa5-4c2d15fddbe9' ";
string oldMapping = "xmlns:ns0='http://schemas.microsoft.com/office/2006/metadata/properties' xmlns:ns1='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns2='http://schemas.microsoft.com/office/infopath/2007/PartnerControls' xmlns:ns3='7ca6dbc0-d9b0-4537-9086-2a91977d7b1f' xmlns:ns4='ae4be937-cb3c-4f60-b399-98f3520c7956' xmlns:ns5='b3dfade7-fa66-4fea-9a5f-8238240f27a6' xmlns:ns6='http://schemas.microsoft.com/sharepoint.v3' ";
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
{
string docText = null;
using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
{
docText = sr.ReadToEnd();
}
var tempDocText = docText.Replace(oldMapping,newMapping);
using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
{
sw.Write(tempDocText);
}
var futt = wordDoc.MainDocumentPart.FooterParts;
}
}
I tried also change it directly in each footer as you can see with var futt, but with same result. Is there other way to edit?