Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

This might seem like a dumb question, but I just can't figure out what is wrong with my code, because it always worked and is working when I debug.

I have a pdf file that I am displaying using the webbrowser control. Now the path to the pdf should be the installation directory where my application is installed. The thing is it is placing the pdf there, but my code cannot find the file. However when I display the path in a textbox it is pointing to the file in my install directory. So I am totally lost.

This is my code:

C#
private void btnGettingStarted_Click(object sender, EventArgs e)
        {
            GeneralLoader.ShowSplashScreen();
            _viewModel.OpenPDFViewer("Getting Started", AppDomain.CurrentDomain.BaseDirectory + "PDF Files\\Getting_Started.pdf");
            GeneralLoader.CloseForm();
        }


That goes to a class with the following code:

C#
public void OpenPDFViewer(string name, string pdfUrl)
        {
            PDFViewer viewer = new PDFViewer(name, pdfUrl);
            viewer.Show();
        }


And the PDFViewer form has the following code:

C#
public partial class PDFViewer : Form
    {
        string PDFName;
        string PDFUrl;

        public PDFViewer(string name, string pdfUrl)
        {
            InitializeComponent();
            PDFName = name;
            PDFUrl = pdfUrl;
            LoadDocument();
        }

        public void LoadDocument()
        {
            this.Text = PDFName;
            PdfDocument.Navigate(PDFUrl);
        }

        private void PDFViewer_Load(object sender, EventArgs e)
        {
            this.Activate();
        }
    }


I cannot seem to find the answer to this problem. the path to the pdf just won't work after application is deployed, but when the application is being debugged, then it is working fine.

Any help would be appreciated.
Posted

The most likely reason is that it's a permissions issue: in development, then whole folder your app is executing under is normally pretty open to all. In production, the application is installed in the "Program Files" folder, which is a lot, lot less accessible - and likely to become more restricted, not less, in the future.

Try an experiment: write the PDF file to the "Application Data" folder: Where should I store my data?[^] and try it from there. Since that is an "open" directory, the chances are the PDF reader will have the required access the folder and file.
 
Share this answer
 
This is the most reliable way to get the executable directory of some application ("installation" is totally irrelevant), explained in my past answer:
How to access a file from html folder of root directoty[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900