简体   繁体   中英

programmatically opening adobe but pdf won't load

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;
}

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM