我的安装目录C#的路径 [英] Path to my Installation Directory C#

查看:118
本文介绍了我的安装目录C#的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这似乎是一个愚蠢的问题,但是我无法弄清楚我的代码出了什么问题,因为它始终有效并且在我调试时仍有效.

我有一个使用webbrowser控件显示的pdf文件.现在pdf的路径应该是我的应用程序的安装目录.问题是将pdf放置在那里,但是我的代码找不到该文件.但是,当我在文本框中显示路径时,它指向我的安装目录中的文件.所以我完全迷路了.

这是我的代码:

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:

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:

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



而且PDFViewer表单具有以下代码:



And the PDFViewer form has the following code:

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



我似乎找不到这个问题的答案. pdf的路径在部署应用程序后将不起作用,但是在调试应用程序时,它可以正常工作.

任何帮助将不胜感激.



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.

推荐答案

最可能的原因是它是一个权限问题:在开发中,那么您的应用程序在其下执行的整个文件夹通常都很漂亮向所有人开放.在生产环境中,该应用程序安装在"Program Files"文件夹中,该文件夹很多时候都不能访问,并且在将来可能会变得越来越受限制,而不是更少.

尝试一下实验:将PDF文件写入应用程序数据"文件夹:应在哪里我存储数据了吗? [ ^ ],然后从那里尝试.由于这是一个打开"目录,因此PDF阅读器将具有所需的访问文件夹和文件的权限.
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.


这是获取某些应用程序的可执行目录的最可靠方法. (与安装"完全无关),在我过去的回答中解释过:
如何从以下位置访问文件根目录根目录的html文件夹 [
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


这篇关于我的安装目录C#的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆