none
C# open PDF File Not Found error all the time RRS feed

  • Question

  • No matter what I do I can't get a PDF to simply open in C#.

    I tried so many combinations of Process.Start with defining startinfo no startinfo, many attempts with double quotes, @ symbols etc...why is this so hard. Seems like it should just work.

    This works great!!! Hard path.

    Process.Start(@"C:\Lely Files\Milking and cooling software set 2018-39\Astronaut A5 v1.5 (b7)\documentation\Milking and cooling software set 2018-39.pdf");

    This is wrecking my life, hours trying to get it to work, since my .exe can be anywhere on the PC I want to get current path and navigate to a nested path to a PDF or EXE and simply open them.

            public string currentpath = System.IO.Directory.GetCurrentDirectory();
            //public string currentpath = System.IO.Path.GetDirectoryName(Application.ExecutablePath).ToString(); Tried this, no luck.
            string fullpath;
            string fullfile;

            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("Current Path " + currentpath);
                string filename = @"Milking and cooling software set 2018-39.pdf";
                fullpath = currentpath + @"\Astronaut A5 v1.5(b7)\documentation\";
                MessageBox.Show("fullpath " + fullpath);
                fullfile = fullpath + @filename;
                MessageBox.Show("fullfile " + fullfile); CORRECT PATH to PDF File!! YES IT EXISTS THERE!!
                Process.Start(fullfile); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!Keeps failing here even though the messagebox shows CORRECT PATH!

                //Process.Start(@"C:\Lely Files\Milking and cooling software set 2018-39\Astronaut A5 v1.5 (b7)\documentation\Milking and cooling software set 2018-39.pdf");
            }

    Please help! Can't be that hard to Get current path where my EXE is launched, then combine current path with path to PDF and open the PDF!!!!


    • Edited by Domleg Monday, October 22, 2018 1:28 AM
    Monday, October 22, 2018 1:27 AM

Answers

  • Probably a space is required before “(b7)”. Try this:

    string startup_path = Application.StartupPath;

    string subfolder = @"Astronaut A5 v1.5 (b7)\documentation";

    string filename = "Milking and cooling software set 2018-39.pdf";

    string full_path = Path.Combine( Path.Combine( startup_path, subfolder ), filename );

    MessageBox.Show( full_path );

    Process.Start( full_path );

     

    If your application is located in “Astronaut A5 v1.5 (b7)”, then:

    string subfolder = @"documentation";

     

    To avoid problems, copy the exact names from File Explorer.

    Monday, October 22, 2018 5:09 AM

All replies

  • Probably a space is required before “(b7)”. Try this:

    string startup_path = Application.StartupPath;

    string subfolder = @"Astronaut A5 v1.5 (b7)\documentation";

    string filename = "Milking and cooling software set 2018-39.pdf";

    string full_path = Path.Combine( Path.Combine( startup_path, subfolder ), filename );

    MessageBox.Show( full_path );

    Process.Start( full_path );

     

    If your application is located in “Astronaut A5 v1.5 (b7)”, then:

    string subfolder = @"documentation";

     

    To avoid problems, copy the exact names from File Explorer.

    Monday, October 22, 2018 5:09 AM
  • Posting the exception message would be helpful.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, October 22, 2018 2:14 PM
    Moderator
  • Hello, 

    Try few simple things:

    - put file into - C:\00\a.pdf - and see if it can be opened.

    - put file into - c:\0 0\A B.pdf - (two spaces in full name) and see if it can be open.

    If first didn't work - need to check file extension associations.

    IF second didn't work - system can't handle spaces in filename - need to double quote fullfilename.


    Sincerely, Highly skilled coding monkey.

    Monday, October 22, 2018 2:36 PM
  • Yep, that was it, can't believe I didn't catch that space missing..thanks! Weird thing is, I did copy from File Manager, must have hit a delete by accident when coding.

    Tuesday, October 23, 2018 3:54 AM