I am having trouble saving the word document in C#. the text is pasted in the word document, however saving the file is the problem.
wordDoc.Application oWord;
wordDoc.Document oDoc;
oWord = new wordDoc.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add();
Clipboard.SetText(_Text);
oDoc.ActiveWindow.Selection.Paste();
string fileName = @"C:\Users\Sam\Documents\NewDocument.docx";
oWord.Application.ActiveDocument.SaveAs2(fileName);
oDoc.Close();
The error that occurs is "Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I believe it's the copying of the rich text box.
UPDATE I copied the contents from the rich text box and performed the method manually and this saved with no errors.
Mohsen
System.Windows.Forms.RichTextBox rtb = new System.Windows.Forms.RichTextBox();
rtb.Text = _Text;
rtb.SaveFile(@"C:\Users\Sam\Documents\NewDocument.rtf");
Ken Brittain
Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application();
//Set animation status for word application
winword.ShowAnimation = false;
The error also occurs on ShowAnimation i am using office 2007, however i could be using any version of office.