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.