I created a temp folder on my C: for easy navigation via the command prompt. I did as Cindy posted I needed to create an my own IA for Word 2000. Ref matchKashida ,ref matchDiacritics, ref matchAlefHamza, ref matchControl) Ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace, Line = line.Replace("", textBoxInspBy.Text) Įdit: Here is my find and replace method private void FindAndReplace(.Application doc, object findText, object replaceWithText)ĭoc.(ref findText, ref matchCase, ref matchWholeWord, Line = line.Replace("", textBoxCalBy.Text) Line = line.Replace("", textBoxSerial.Text) Line = line.Replace("", textBoxModel.Text) Using (StreamReader sr = new StreamReader(templateFilePath)) StreamWriter sw = new StreamWriter(textBoxSaveFilePath.Text) Using StreamWriter private void method2() enc = new ASCIIEncoding() įile.WriteAllText(textBoxSaveFilePath.Text, text, ) Text = text.Replace("", textBoxInspBy.Text) Text = text.Replace("", textBoxCalBy.Text) Text = text.Replace("", textBoxSerial.Text) Text = text.Replace("", textBoxModel.Text) String text = File.ReadAllText(templateFilePath) String templateFilePath = .StartupPath + "\\AIO2CertTemplate.doc" This.FindAndReplace(wordApp, "", textBoxInspBy.Text) ĪDoc.SaveAs(ref saveFileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing) This.FindAndReplace(wordApp, "", today.ToShortDateString()) This.FindAndReplace(wordApp, "", textBoxCalBy.Text) This.FindAndReplace(wordApp, "", textBoxSerial.Text) This.FindAndReplace(wordApp, "", textBoxModel.Text) Object saveFileName = textBoxSaveFilePath.Text ĪDoc = (ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing) Object fileName = .StartupPath + "\\AIO2CertTemplate.doc" _Application wordApp = new .Application() Great! So how would I do this with my program? I've tried using the File class and I've tried StreamWriter but both save the files as garbage so when I try to open them with word they ask me for what encoding I am using, and that doesn't seem to work.Īny idea what encoding I need to use? or how does Notepad++ able to edit the doc and save it in the correct format? //Using Microsoft Office Interop Word Then when I open the saved doc, it looks great. So I tried opening the template doc in Notepad++, it opens fine, it had a bunch of weird letters and stuff, but I can find/replace my values and save. Problem is, the environment I need it to work on is using Word 2000 and upgrading it isn't an option because 2000 is needed for some other programs on that PC. I've tried using and things work really well, if Office 2003 or greater is installed on the environment. I'm trying to edit a word doc template and searching for specific strings and replacing them with values from my C# program.