This project has moved and is read-only. For the latest updates, please go here.

ReplaceText and AddCustomProperty

Mar 15, 2011 at 4:23 PM

Took me forever to find this tool but now that I have it I'm hooked.  Dropped my code from 50 lines to about 7.  Awesome.

Using version 1.0.0.11

Now... if you could help a newb out I'd appreciate the help. 

Problem 1: I've created the following code and can read in, replace the text just fine, but it does not keep my formatting. What am I missing or is this just a bug? 

Problem 2: I cannot seem to be able to find and replace any of the document properties within my document.  I've looked at the document itself and I believe have have the right tag name, but this doesn't seem to do anything.

        protected void exeProcessTheDoc(object sender, EventArgs e)
        {
            string doc1 = Server.MapPath("~/Templates/file1.docx");
            string doc2 = Server.MapPath("~/Templates/file2.docx");

            GetPropertyFromDocument(doc1, doc2);
        }

        public static void GetPropertyFromDocument(string document, string outdoc)
        {
            File.Delete(outdoc);
            File.Copy(document, outdoc);
            using (DocX doc = DocX.Load(document))
            {
                doc.ReplaceText("{Company Name}", "Some Company Name");
                doc.AddCustomProperty(new CustomProperty("Subtitle", "Testing 1-2-3"));
                doc.SaveAs(outdoc);
            }
        }

Any help would be much appreciated.

-Petronius