Print Word Document in C# – MS Office on Windows 64 bit Operation System – Error when you try Open Word Document or Print Word Document inside C#

24 במרץ 2011

When you try Open Word Document or Print Word Document inside C# Application


on Windows 64 Operation System, you receive COM Object Error.


For Example:


object wordFileName = "c:\\temp\\test.docx";

object unknown = System.Reflection.Missing.Value; object missing = Type.Missing;

object readOnly = false;


ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();


wordApplication.Visible = false;


// you may receive exception in next line


Document wordDoc = wordApplication.Documents.Open(ref wordFileName, ref unknown, ref readOnly, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown, ref unknown);

wordApplication.Application.Visible = false;

wordApplication.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;

object background = false;

object printToFile = false;

object printAllDocument = Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument;

object item = Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent;

object copies = 1;

// you may receive exception in next line 

wordApplication.PrintOut(
ref background, ref missing, ref printAllDocument, ref missing, ref missing, ref missing, ref item, ref copies, ref missing, ref missing, ref printToFile, ref missing, ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing, ref missing);


For solving this problem goto to folder C:\Windows\SysWOW64\config\systemprofile and


create new folder with name Desktop.


After adding this folder Exception is disappeared.

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *