App.Path in VB.NET
I know VB.NET does not support App.Path, so i found this bit of code:
its instructions say copy and Unlike app.path in vb6, this includes the the "\" at the end of the value.
Public Function App_Path() As String
I dont understand what it mean by "\", can anyone advise?
In VB6, App.Path only includes a backslash (\) at the end of the path if the app is running in the root directory of the drive. That is, if the app is running in the root directory of drive C:, App.Path returns "C:\". If, on the other hand, the app is running in C:\Program Files\My App, App.Path returns "C:\Program Files\My App" (no backslash at the end). Because of this discrepancy, you need to check for the presence of a trailing backslash before appending a file name to the path.
Your VB.NET App_Path function returns a trailing backslash in all cases -- "C:\" or "C:\Program Files\My App\" -- so you may simply append a file name without checking for a backslash.
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
The "real" replacement for App.Path is the following:
VB.NET also offers a second option that returns the working directory at the start of the application:
Going through the AppDomain works most of the time, but an AppDomain and an Application are not the same, and in some cases, the code you used could link to something else than the directory you are looking for.
The replacement Application.ExecutablePath delivers the path of the executable, but not of the dll. If you need the path of the dll that was called as an addin inside of an application (to read config files or whatever) you have to do it this way:
Public Function App_Path() As String
App_Path = CStr(Nothing)
App_Path = System.Reflection.Assembly.GetExecutingAssembly.GetName().CodeBase
If StrComp(LCase(Left(App_Path, 8)), "file:///") = 0 Then
App_Path = Mid(App_Path, 9) 'file:/// entsorgen
App_Path = StripFileName(App_Path)
Reply on use of ExecutablePath vs. StartupPath
Just a quick "Thank You" as this answered my question/solved my problem. However, to provide a bit further info, in VB.NET 2002 at least (net 1.1) I found that Application.ExecutablePath was not useful, as it had not only the path, but included the executable file name as well, which I would have had to strip, however, the other suggestion: Application.StartupPath worked perfectly.
Glad to help.
A little trick that, once again, shows that a lot of things are simpler than they might appear at first sight. You can easily strip the file name from a full name to retrieve only the path:
App_Path = New System.IO.FileInfo(Application.ExecutablePath).DirectoryName
Again, thank you JBourgeois,
The technique using ".DirectoryName" was a very nice approach that I was completely unaware of (not suprising as I'm rather new to .NET - I was a "crusty" VB6'er for far too long ~8^D). I don't know how many times I've done the 'ol "instr" searching for the last "\" and fussing the path from a full file spec string.
One quick question! Why are you using 'New' ?
Originally Posted by JBourgeois
If FileInfo().DirectoryName returns a string and App_Path is a string then why would you need the 'New' in this statement?
Thank you! I will check it out.
Last Post: 11-06-2002, 02:42 PM
Last Post: 10-05-2002, 04:34 PM
By Michael Culley in forum .NET
Last Post: 06-19-2002, 09:11 AM
By Bill McCarthy in forum .NET
Last Post: 04-10-2001, 05:03 AM
By David Kroll in forum .NET
Last Post: 02-13-2001, 10:23 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center