edit part of databindings in word footer

Ondřej Čech 1 Reputation point
2021-02-04T15:55:33.42+00:00

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?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,573 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,684 questions
{count} votes