Click here to Skip to main content
15,885,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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.
Posted
Updated 28-Dec-14 22:57pm
v4
Comments
Maciej Los 29-Dec-14 2:18am    
What it means: "not working"?
Tejas Vaishnav 29-Dec-14 2:27am    
Where are you using, are you using any code from interop to accomplish your task, then what was the error you got, can you update your question with your code block or any error message, you can use "improve question" functionality to update your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900