I have a wordfile that I want to replace a text in. I use the following code:
WordDocumentrebarTemplate=newWordDocument();
rebarTemplate.Open(textBox1.Text,FormatType.Automatic);
rebarTemplate.Replace("%1%_P:RebarChecked","newvalue",false,true);
Directory.CreateDirectory(@"C:\temp\synctest\");
rebarTemplate.Save(@"C:\temp\synctest\syncreplace.docx");
rebarTemplate.Close();
I get the argumentoutofrangeexception 'startIndex cannot be larger than length of string.' when the replace line is called.
I get this exception from the original file.
However, if I open the word file in word 2013 and alter one or more of the texts and save it, the code runs ok.
The original word file open correctly in word 2013.
Any idea what may be wrong?
See the attached file...
Regards
Øyvind Knappskog Olsen
Norconsult Informasjonssystemer AS