在C#Windows应用程序中访问bin文件夹及其并行文件夹中的文件(未提供完整路径). [英] Accessing a File within bin folder and its parallel folders in c# windows application (Not giving full path)..

查看:87
本文介绍了在C#Windows应用程序中访问bin文件夹及其并行文件夹中的文件(未提供完整路径).的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过c#代码访问chm文件,该文件存储在与Visual Studio 2005中C#Windows应用程序的/bin文件夹平行的文件夹中.我不想提供完整的路径,例如c:\\ Program文件\\ .. \\.它应该类似于Application.Startup,它会导致我们的应用程序的调试文件夹.请提出建议.

I want to access through c# code a chm file stored inside a folder which resides parallel to /bin folder of my C# windows application in Visual Studio 2005. I don''t want to give full path like c:\\Program Files\\..\\. It should be like Application.Startup which leads to debug folder of our application. Please advice.

推荐答案

您绝对不希望使用绝对路径.在任何情况下都不应该.对于帮助文件,这是相对于您的应用程序入口程序集的主模块目录(可能要缩进的位置)进行定位的最佳方法.

您可以找到这样的二进制路径:

You''re absolutely right that you don''t want to use absolute path. Under no circumstances you should. For help files, the best way to locate them relative to the directory of the main module of the entry assembly of your application (which you probably indent to do).

You can find you binary path like this:

string binaryPath =
     System.IO.Path.GetDirectoryName(
         System.Reflection.Assembly.GetEntryAssembly().Location);



(顺便说一句,PrivateBinPath(在其他答案中引用)是100%与之无关的.此字符串显示了放置专用程序集的目录列表.可能您没有任何目录,然后PrivateBinPath将返回null.很难找到与null字符串有关的任何东西:))

--SA



(By the way, PrivateBinPath (referred to in other answer) is 100% irrelevant to this. This string shows a list of directories where you put private assemblies. Probably, you don''t have any, then PrivateBinPath will return null. It would be pretty difficult to find anything relative to null string :) )

--SA


让我们说一下您当前是否在C:/fakepath/MyProject/Modules/文件夹中.
Bin文件夹位于以下位置:C:/fakepath/MyProject/bin/
CHM文件位于以下位置的文件夹中:C:/fakepath/MyProject/HelpFiles/

然后尝试类似的操作:
"../HelpFiles/ABC.CHM"

您只需要进入父文件夹级别,然后移至所需的路径即可.务必确保您可以访问该文件夹.
Lets, say if you are currently at C:/fakepath/MyProject/Modules/ folder.
Bin folder is at location: C:/fakepath/MyProject/bin/
CHM file in a folder at location: C:/fakepath/MyProject/HelpFiles/

Then try something like:
"../HelpFiles/ABC.CHM"

You just need to go at parent folder level and then move to the desired path. Make sure you have access to that folder though.


感谢,它的工作和目的已经解决,但我仍然想知道,按照您提供的命令,我们到达了可执行位置,但/bin目录仍然比它低一级.我们可以访问位于bin文件夹级别的任何文件夹吗?因为只是为了知识.
Thanks, its working and purpose is solved but still I want to know that as per your provided command we reached to executable location but /bin directory is still one level down from it. Can we access any folder which lies on the level of bin folder. Since Just for knowledge sake.


这篇关于在C#Windows应用程序中访问bin文件夹及其并行文件夹中的文件(未提供完整路径).的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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