Мысли вслух…

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. 

Check for directory:

<SystemDrive>:\Windows\SysWOW64\config\systemprofile\Desktop — x64

<SystemDrive>:\Windows\System32\config\systemprofile\Desktop — x86

:,

Leave a Reply

:bad: :beer: :biggrin: :blink: :blush: :bomb: :confused: :cool: :crazy: :cry: :dont_know: :eek: :evil: :dance: :heart: :idea: :joke: :kiss: :lol: :mad: :music: :rose: :sad: :smile: :surprised: :tongue: :yahoo: :wall: :wink:
 

Поиск

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