1
votes

So I have code to open a pdf programmatically. the code opens adobe reader just fine, but I get a dialog that pops up that says the file doesn't exsit. The problem is though that I can browse to the exact path that is being used to try and open the pdf in a windows explore, plus there is an if statement for if the file exists. So why isn't adobe opening the pdf?

the path for the Adobe .exe on the proc.StartInfo.FileName is correct.

I found this link: https://visibleprocrastinations.wordpress.com/2009/08/20/there-was-an-error-opening-this-document-file-cannot-be-found-acrobat-reader/ but I don't know if it still applies

PDF file path:

C:\Users\Printer\SharePoint\Partners - Doc\McG\Labels\TR109897\eLabels_TR109897.pdf

Heres the code I'm using:

Process proc = new Process();

FileInfo file = new FileInfo(filepath);

if (file.Exists)
{
    //Define Location of adobe reader/command line
    proc.StartInfo.FileName = @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    proc.StartInfo.Arguments = string.Format(@"{0}", file.FullName);
    proc.StartInfo.UseShellExecute = true;
    proc.StartInfo.CreateNoWindow = true;

    proc.Start();

    if (proc.HasExited == false)
        proc.WaitForExit(10000);

    proc.Close();
    return true;
}
1
First, Process only works on the local machine. If you have it in a web application, then the process will occur on the server, not the user's pc. Look into saving the "temp" pdf file to the users temp folder and opening it from there. You will have to look into streaming. - Zath
It's on a local machine. - B-M
Not WPF specific, removed the tag. - Dean Kuga

1 Answers

2
votes

It sounds like the shell is parsing up your filename in an unintended way. Try wrapping your filename in quotes:

proc.StartInfo.Arguments = string.Format("\"{0}\"", file.FullName);