VB.NET ==> getting the path to current directory?

2008-02-12 3:25 pm
my main folder is on desktop and im trying to get the path to a text file in my main directory. I use this code"
System.Environment.CurrentDirectory
and it returns :
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE
and that's not the path to my current directory
the current direcotory that my aspx file is located in is:
C:\Documents and Settings\USER\Desktop\asd\

any help?

回答 (3)

2008-02-12 3:31 pm
✔ 最佳答案
If you want to use the folder in which the program resides, use the following code:

Public SetupFile As String = Application.ExecutablePath

This way, no matter WHERE the program is residing, the path will be to that folder.

If you want it to go specifically to "C:\Documents and Settings\USER\Desktop\asd\", just set "SeupFIle" to "C:\Documents and Settings\USER\Desktop\asd\"

Public SetupFile As String = "C:\Documents and Settings\USER\Desktop\asd\"

I hope I interpreted your question correctly. Good luck.
2016-12-12 5:28 pm
Vb.net Directory
2008-02-12 3:42 pm
This first post is correct. Application.ExecutablePath will get you the current path of the running application.

'sorry I have to break this down into lines so it would fit in Yahoo! Answers.
Dim UserProfile as string = System.Enviroment. _
GetEnviromentVariable _
("%USERNAME%")

'this will get you the user profile of the current user
'in your case the UserProfile string would equal
"C:\Documents and Settings\[UserName]"

Then just add you folder
ApplicationFolder = UserProfile & "\Desktop\asd"

The nice part about doing it this way. Is that if you run this on vista the enviroment variable will return
"C:\Users\[UserName]"

instead of hard coding a value into your program.


收錄日期: 2021-04-30 23:19:31
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080212072506AAykqw7

檢視 Wayback Machine 備份