My Code for mail merge
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
wordApp.Visible = false;
wordApp.ScreenUpdating = false;
object filename = path;
object newFileName = @"~\Quotation\Quotation\document_to_read_tomorrow1.pdf";
object missing = System.Type.Missing;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Add(Template: filename);
foreach (Microsoft.Office.Interop.Word.Field field in doc.Fields)
{
string fieldName =GetFieldName( field.Code.Text);
if (dataToWrite.ContainsKey(fieldName))
{
field.Select();
string value = dataToWrite[fieldName].ToString();
wordApp.Selection.TypeText(value);
}
}
object formatoArquivo = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
doc.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4;
doc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;
doc.SaveAs(ref newFileName, ref formatoArquivo, 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, ref missing);
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
((_Document)doc).Close(ref saveChanges, ref missing, ref missing);
doc = null;
((_Application)wordApp).Quit(ref missing, ref missing, ref missing);
wordApp = null;
return newFileName.ToString();
when i run in my local system its fine but when i run in server it throwing error
Could not load file or assembly 'Microsoft.Office.Interop.Word, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
Then I loaded the assembly to bin folder then I got an error
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154.
[Edit member="Tadit"]
Added
pre
tags.
[/Edit]