I have installed microsoft office interopp 12.0.0.0 version in dotnet 2005 version. But it is not working and am using office 2007. I am using this ddl file for converting .docx file to pdf file.
My code is shown below.
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object oMissing = System.Reflection.Missing.Value;
DirectoryInfo dirInfo = new DirectoryInfo(@"D:\Doc");
FileInfo[] wordFiles = dirInfo.GetFiles("*.docx");
word.Visible = false;
word.ScreenUpdating = false;
foreach (FileInfo wordFile in wordFiles)
{
Object filename = (Object)wordFile.FullName;
if (wordFile.ToString() == "Offer letter.docx")
{
Document doc = word.Documents.Open(ref filename, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
object outputFileName = wordFile.FullName.Replace(".docx", ".pdf");
object fileFormat = WdSaveFormat.wdFormatPDF;
doc.SaveAs(ref outputFileName,
ref fileFormat, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
doc = null;
}
}
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
It is giving error as "Command Failed".
Please help me is there any lower versions for my office 2007 version and My microsoft office is 2007.Please suggest me.