Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is something that I have tested Make sure that you do not stop the debugger until you have gotten to the <code>Marshal.Release code and GC.Collect</code></p> <p>I have office 2010 but in your using section add the following</p> <pre><code>using Word = Microsoft.Office.Interop.Word; using System.Runtime.InteropServices; </code></pre> <p>this is how you implement <code>namespace Aliasing</code></p> <p>here is the code below </p> <pre><code>var fileName = "TestDoc.docx"; Object oMissing = System.Reflection.Missing.Value; var oTemplatePath = @"C:\Documents\wrkDocuments\" + fileName; var wordApp = new Word.Application(); var originalDoc = wordApp.Documents.Open(@oTemplatePath); originalDoc.ActiveWindow.Selection.WholeStory(); originalDoc.ActiveWindow.Selection.Copy(); var newDocument = new Word.Document(); newDocument.ActiveWindow.Selection.Paste(); newDocument.SaveAs(@"C:\Users\Documents\wrkDocuments\TestDoc2.docx"); System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp); System.Runtime.InteropServices.Marshal.ReleaseComObject(originalDoc); System.Runtime.InteropServices.Marshal.ReleaseComObject(newDocument); GC.Collect(); </code></pre> <p>Alter this Method that I have created for you and pass in the proper params </p> <pre><code>private static void CopyWordDoc() { var fileName = "TestDoc.docx"; Object oMissing = System.Reflection.Missing.Value; var oTemplatePath = @"C:\Documents\wrkDocuments\" + fileName; var wordApp = new Word.Application(); var originalDoc = wordApp.Documents.Open(@oTemplatePath); // you can do the line above by passing ReadOnly=False like this as well //var originalDoc = wordApp.Documents.Open(@oTemplatePath, oMissing, false); originalDoc.ActiveWindow.Selection.WholeStory(); originalDoc.ActiveWindow.Selection.Copy(); var newDocument = new Word.Document(); newDocument.ActiveWindow.Selection.Paste(); newDocument.SaveAs(@"C:\Documents\wrkDocuments\TestDoc2.docx"); System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp); System.Runtime.InteropServices.Marshal.ReleaseComObject(originalDoc); System.Runtime.InteropServices.Marshal.ReleaseComObject(newDocument); GC.Collect(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload