Saturday, November 20, 2010

How to remember the directory path with VB.net without hardcoding the path name to a variable?

I would like to find out whether there is anyway to remember a directory path without hardcoding the path name to a variable. This will allow me to change the directory path easily without changing the code.How to remember the directory path with VB.net without hardcoding the path name to a variable?
if it helps, use GetCurrentDirectory() method in System.IO namespace. you can change the directory later in the code as you like. refer to sample in msdn.



Dim path As String = Directory.GetCurrentDirectory()





http://msdn.microsoft.com/en-us/library/How to remember the directory path with VB.net without hardcoding the path name to a variable?
I presume you mean you want the directory to where your software is:



You want to reference the Application.StartupPath property. This will tell you where the launched the application from and then your application's directories remain dynamic. To refer to a subdirectory you could use something like:



Application.StartupPath %26amp; ';\bin';
There are a couple of really easy ways. One is to use SaveSetting and save the path name to the registry, and use GetSetting to retrieve it. The second way is to write it to a file.

No comments:

Post a Comment