Мысли вслух…

Архив за Май, 2012

WindowsService and MS Word

Пользователь Май.22.2012. Категория Development

Good day, a few days ago I’ve started to develop WindowsService for building doc/docx documents.

My code for calling MS Word.

var wordApplication = new Application
{
DisplayAlerts = WdAlertLevel.wdAlertsNone,
Visible = true
};
Document wordDocument = null;
var resultPath = Path.Combine(ResultDirectory, Path.GetFileNameWithoutExtension(FileName) + ".pdf");
try
{
wordDocument = wordApplication.Documents.OpenNoRepairDialog(FileName);
if (wordDocument == null)
{
throw new InvalidOperationException("Cannot load document to MS Word Instance");
}
wordDocument.ExportAsFixedFormat(resultPath, WdExportFormat.wdExportFormatPDF);
}
finally
{
if (wordDocument != null)
{
wordDocument.Close();
}
wordApplication.Quit();
GC.Collect();
GC.WaitForPendingFinalizers();
}

So, I’ve got a trouble, when I called method Open or OpenNoRepairDialog I’ve got null.

  • I’ve tried to set permissions for DCOM;
  • I’ve tried to use impersonation (just for test);
  • I’ve tried to lunch my Windows Service under user with administrative privileges;

Solution below.  (читать дальше…)

Оставить комментарий :, дальше...

Поиск

Список друзей