0

Running on Windows 10 I have a C# program that (among other things) opens, modifies, and writes a Word document (docx, not doc). It works fine from the command line. But run in Jenkins, the Documents.Open() call returns null

I have read the following on StackOverflow: Unable to open word document from jenkins open word doc with c# Interop.Word Documents.Open is null

I have added C:\Windows\System32\config\systemfile\Desktop and C:\Windows\SysWOW64\config\systemfile\Desktop Result: program hangs on Documents.Open (System32 didn't change anything; SysWOW64 resulted in the hang)

using Word = Microsoft.Office.Interop.Word;

// … lots of stuff

var wordApplication = new Word.Application();

wordApplication.Visible = false;
Word.Application wordApp = null;
if (wordApplication != null)
    wordApp = wordApplication as Word.Application;
Word.Document wordDoc = null;
if (wordApp != null){
    if(!IsFileinUse(reportPath))
    {
        // this line is the problem.
        // It works from the command line
        // In Jenkins, it either returns null or hangs
        wordDoc = wordApp.Documents.Open(reportPath.FullName);
    }
}

I expect it to behave in Jenkins as it does from Command Prompt: open the file successfully and allow the operations -- not hang or return null.

TheBick
  • 341
  • 1
  • 5
  • 12
  • 1
    Why are you using office interop and not [OpenXML](https://www.nuget.org/packages/DocumentFormat.OpenXml/)? Office interop [is not supported for servier side applications](https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office) like jenkins. – Scott Chamberlain Mar 27 '19 at 00:49
  • You cannot run *interactive* applications as BACKGROUND process. Maybe if you suprime the *open* step, your program could be work – JRichardsz Mar 27 '19 at 01:26

0 Answers0