Search and replace in a file – in memory

Home Forums Open-Xml-PowerTools Search and replace in a file – in memory

This topic contains 2 replies, has 2 voices, and was last updated by  Eric White 8 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3730

    gamartin
    Participant

    OK I was able to get this to work in memory. I guess the behaviour when you save the file is different than when you just work in memory.

    I if do it thusly it works:

     // open our template and do our quick search and replace
                var templateDoc = new WmlDocument(templatePath);
                
                templateDoc = TextReplacer.SearchAndReplace(templateDoc, "<TitlePageGroupAndCode>", _caTitle, true);
                templateDoc = TextReplacer.SearchAndReplace(templateDoc, "<TitlePageBargainingAgentName>", _bargainingAgentName, true);
                templateDoc = TextReplacer.SearchAndReplace(templateDoc, "<TitlePageGroupName>", _groupName, true);
                templateDoc = TextReplacer.SearchAndReplace(templateDoc, "<TitlePageExpiryDate>", _expiryDate, true);
                templateDoc = TextReplacer.SearchAndReplace(templateDoc, "<CopyrightBargainingAgentName>", _bargainingAgentName, true);
                

    Cheers,

    Garth

    #3768

    Eric White
    Keymaster

    Great, glad you got it working.

    Check out this MSDN article:

    https://msdn.microsoft.com/en-us/library/ee945362(v=office.11).aspx

    Cheers, Eric

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.