In a web application i have to implement a method to convert a doc/docx to a PDF. This is how i am doing it:
FileInfo FILE = new FileInfo(path + filename);
object missing = System.Reflection.Missing.Value;
object readOnly = false;
object objfilename = (object)FILE;
//Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
try
{
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
// var wordDocument = appWord.Documents.Open(FILE);
var wordDocument = appWord.Documents.Open(ref objfilename,
ref missing, ref readOnly, 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);
wordDocument.ExportAsFixedFormat(@"C:\Users\ABCD\Desktop\New folder\DocTo.pdf", WdExportFormat.wdExportFormatPDF);
But the code breaks on Documents.Open line and the error that it displays is:
[System.Runtime.InteropServices.COMException] = {"Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"}