1

I've added a pdf file to my application as a content, and I'm trying to get it to launch when a button is clicked but I'm not too sure why it doesn't want to work.

Here's the code:

private void AppDoc_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            Uri uri = new Uri("/UserGuide_PDF.pdf", UriKind.Relative);
            System.Diagnostics.Process.Start(uri.LocalPath);
        }
        catch
        {
            MeBox.Show("The file location could not be found.", "Location Not Found", MessageBoxButton.OK, MessageBoxImage.Warning);
        }

I get an exception that says "System.InvalidOperationException" Any suggestions?

kknaguib
  • 749
  • 4
  • 12
  • 33
  • 4
    What doesn't work - are you getting an exception? If so can you paste the exception content. – Jay Feb 13 '14 at 13:22
  • 2
    It seems like your pdf file is marked as resource. Since resource files are not individual files on hard disk, Process.Start may fail. Maybe you should try marking it as not Resource and use directly System.Diagnostics.Process.Start(@"somePath"); – mcy Feb 13 '14 at 13:22
  • yea please take a look above I edited it @Jay – kknaguib Feb 13 '14 at 13:42
  • I need the file to be attached to my project so when I publish it, it will launch regardless of the location shouldn't setting it as a resource file do that? @mcy – kknaguib Feb 13 '14 at 13:44
  • Well in order to do what you described, I set Build Action to "None", Copy to Output "Directory Copy if newer", and then in the installer, I add the files under their respective folders (i.e. I create "Resources" folder then I copy the file there). But I use WiX installers instead of publishing them directly. I will have a look for "Content" types – mcy Feb 13 '14 at 13:59
  • Simply `Process.Start(full_path);` should work, assuming `full_path` is a string. May be you have to check, that exactly `uri.LocalPath` returns. – Rocketq Feb 13 '14 at 14:35

0 Answers0