I can not call Process.Start("DocToPDF.exe", "file.docx file.pdf")
successfully from IIS.
- I have tried allowing desktop interaction from IIS Admin Service;
- I have tried granting full control permissions to DefaultAppPool for the directory containing the DocToPDF.exe
None of this worked. The DocToPDF.exe exits with code: 1 (I write the exit code to a file...). When I run the website in debug mode (F5) the program exits with code: 0 and everything is ok. It works perfectly well in debug mode. My guess is it has something to do with IIS permissions or something like that because as I said it works well when launching the application from visual studio.
Here is the method that I am using:
public byte[] DocToPdf(MemoryStream ms)
{
string fileName = Guid.NewGuid().ToString();
string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + fileName + ".docx";
string newPath = path.Replace("docx", "pdf");
FileStream fs = new FileStream(path.ToString(), FileMode.OpenOrCreate);
fs.Write(ms.ToArray(), 0, ms.ToArray().Length);
fs.Close();
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = @"C:\Utils\OfficeToPDF.exe";
p.StartInfo.Arguments = path + " " + newPath;
p.Start();
p.WaitForExit();
System.IO.File.WriteAllText(@"C:\Utils\exitcode.txt", p.ExitCode.ToString());
var bytes = System.IO.File.ReadAllBytes(newPath);
System.IO.File.Delete(path);
System.IO.File.Delete(newPath);
return bytes;
}