This project has moved. For the latest updates, please go here.

ReplaceText and AddCustomProperty

Mar 15, 2011 at 3: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

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.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"));

Any help would be much appreciated.