Thursday, July 30, 2009

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

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?

VB.NET ==%26gt; getting the path to current directory?
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.
Reply: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 %26amp; "\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.


No comments:

Post a Comment