I'm using PDFSharp to create a PDF. In their examples, they save a PDF and then then they start a process to choose your viewer to open it. It looks like this:
document.Save(fileName);
Process.Start(fileName);
So in my testing, I realized that if Acrobat Reader is already open, I get an i/o exception because the process is already running. So I tried following this post: Detecting a Process is already running in windows using C# .net
about detecting the process. So I changed the above code to this:
document.Save(fileName);
if (System.Diagnostics.Process.GetProcessesByName("AcroRd32.exe").Length == 0)
{
Process.Start(fileName);
}
So I have two questions.
1) This doesn't work. The Length is always 0 so I'm wondering if I am returning the wrong process or it can't find the process. When I look in Task Manager, that AcroRd32.exe is the name of the process that is being run.
2) Is there a better way to do this? It seems like I'm hardcoding this process into the code and I wasn't sure if there was a better way to catch either other versions of Acrobat (like if there was a 64-bit version), or other PDF viewers in general.
Sorry if this is noob question. This .NET is pretty new to me. Thanks.