I want to get the latest binding for the following lines of code that use early binding. How can I achieve this in C #?
When I removed the Microsoft.office.interop.word link, I get some errors that are mentioned in the comments in the following code. Folloowing is the code that I use to convert a Word document to pdf.
Type wordType = Type.GetTypeFromProgID("Word.Application");
dynamic Word = Activator.CreateInstance(wordType);
object oMissing = System.Reflection.Missing.Value;
DirectoryInfo dirInfo = new DirectoryInfo(@"\\server\folder");
FileInfo wordFile = new FileInfo(fileName);
Word.Visible = false;
Word.ScreenUpdating = false;
Object filename = (Object)wordFile.FullName;
var doc = Word.Documents.Open(ref filename);
doc.Activate();
object outputFileName = wordFile.FullName.Replace(".doc", ".pdf");
object fileFormat = WdSaveFormat.wdFormatPDF;
doc.SaveAs(ref outputFileName, ref fileFormat);
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges);
doc = null;
Word.Quit();
MessageBox.Show("Successfully converted");
source
share