0

In VS2019, the following code runs CreatePDF.exe by taking input from c:\myFolder\test.txt, and creates a PDF file c:\myFolder\test.pdf. But when when I run the same code from a Microsoft WORD VSTO add-in, I don't see the output PDF file in c:\myFolder folder. That means the add-in is probably creating the pdf file in some other directory. Which directory it may be creating that pdf file in?

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "CreatePDF.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-interaction=batchmode c:\myFolder\test.txt -output-directory=" + c:\myFolder;
startInfo.WorkingDirectory = c:\myFolder;

UPDATE

The above code is from a VSTO project in VS2019. When I run the project from VS2019, it successfully creates a custom ribbon tab along with a button inside it. When you click on that button, it successfully runs the above code and generates a pdf file c:\myFolder\test.pdf from the text file c:\myFolder\test.txt.

But after I run Clean Solution to remove the custom ribbon and then I deploy the project using ClickOnce, the add-in ribbon gets deployed successfully and the other buttons inside the custom ribbon tab perform their task successfully. But the button that runs the above code does not generate the pdf file c:\myFolder\test.pdf (unless it's creating it somewhere else).

nam
  • 21,967
  • 37
  • 158
  • 332
  • Does the directory `c:\myFolder\` exist on the machine you are running the VSTO addin? – aduguid Mar 30 '20 at 06:03
  • Set a breakpoint within your add-in code to use the VS debugger to verify that the process starts and runs – public wireless Mar 30 '20 at 15:22
  • @publicwireless Code works fine inside `VS2019 VSTO Project`. I just added an **UPDATE** section. – nam Mar 30 '20 at 15:28
  • @aduguid For an answer to your question, please see **UPDATE** section to my post that I just added. – nam Mar 30 '20 at 15:48
  • Set breakpoint at your button handler and try attaching the VS debugger to the Excel process at run time (this is an Excel add-in, correct?) OR add code to output each environment variable at runtime https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.environmentvariables?view=netframework-4.8#System_Diagnostics_ProcessStartInfo_EnvironmentVariables – public wireless Mar 30 '20 at 17:00
  • @publicwireless Interesting thought. But I am using WORD add-in. Would you know how to attach VS debugger to the WORD process? – nam Apr 01 '20 at 01:06
  • **RESOLVED**: The whole process is using some supporting files whose `Build Action` in `VS2019` project was set as `None` and `Copy to Output Directory` was set as `Copy if newer`. That worked fine when running the project from `VS2019` but it was failing when the `add-in` was deployed on the system using `ClickOnce`. But after changing the `Build Action` to `Content` it started working on the deployed `add-in` as well. Thank you all who tried to help. – nam Apr 01 '20 at 16:08

0 Answers0