question

Ondejech-5396 avatar image
0 Votes"
Ondejech-5396 asked ·

edit part of databindings in word footer

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
64111-image.png and 64072-image.png
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?




dotnet-csharpoffice-addins-dev
image.png (26.7 KiB)
image.png (25.5 KiB)
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Ondejech-5396 ,
Since your issue is more related to office word development which is out of our scope of support.
I would modify the tag to be “office-addins-dev” and remove 'office-sharepoint-online'.
Thanks for your understanding.

1 Vote 1 ·

0 Answers