开发者

Access a file within a project

开发者 https://www.devze.com 2022-12-16 05:32 出处:网络
In vb.net, when writting an application, I want to access a batch file that has been added to the project. My question is how to I find the relative path of this file to access it?

In vb.net, when writting an application, I want to access a batch file that has been added to the project. My question is how to I find the relative path of this file to access it?

I have used relative path on the ASP.NET side, but not on the application side. The properties that I am finding regarding the current directory and running directory and the likes are all for the bin directory its in. While I can use the CurrentDirectory() property and go 开发者_JAVA技巧up two parents (....) in the development enviroment, when I install the application, the structure is not the same. As in the output is in a single folder, not tiered.

Example. c:\projects\MyApp\bin\debug\MyApp.exe is the running directory My file I want to access is at c:\projects\MyApp\validate.bat so "c:\projects\MyApp" is what I am trying to capture.

Does anyone know how I might attact this issue?


In Visual Studio go to the Solution Explorer, right click the file and select Properties. In the Properties window, change Copy To Output to 'Copy Always' and make sure that 'Build Action' is set to 'Content'.

Now you should be able to access the file using a relative path without using '..' and the file will be in the same relative location whether you run it from the debugger or deployed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号