Trying to set up c# console program that converts pdf to html using Word as intermediary. Works from command line when logged in, but will not do when run from scheduler. Now I know MS do not officially support this- https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office - but no the less I wish to pursue this avenue. I have seen various posts on workarounds, but have failed to get it to work.
In short program stalls at the point of opening the document.
Can anyone advise on what steps can be taken to workaround this MS implemented restriction.
namespace InterOpTest
{
class Program
{
static void Main(string[] args)
{
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
String sFolder = "C:\\temp";
String sInputFile =sFolder+"\\input.pdf";
String sOutputFile = sFolder+"\\test\\output.html";
String sLogFile = sFolder + "\\Interoptest.log";
System.IO.DirectoryInfo d = new DirectoryInfo(sFolder);
// StreamWriter sw= new StreamWriter(sLogFile);
StreamWriter sw = File.AppendText(sLogFile);
try
{
sw.WriteLine("");
sw.WriteLine(DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + ", Deleting any pre-existing version of " + sOutputFile);
File.Delete(sOutputFile);
sw.WriteLine(DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + ", Opening "+sInputFile);
oWord.Documents.Open(sInputFile);
sw.WriteLine(DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + ", saving as " + sOutputFile);
oWord.ActiveDocument.SaveAs2(sOutputFile, FileFormat: 10);
oWord.Quit();
oWord = null;
sw.WriteLine(DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + ", Done");
}
catch (Exception e) {
sw.WriteLine(DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + ", Error :"+ e.Message);
}
finally
{
sw.Close();
Console.WriteLine("Done");
}
}
}
}