i published an application in vb.net. the user will be able to install the application anywhere they choose on the computer (or perhaps not anywhere they choose but where ever the default location is). how can i programmatically get the location where the user installed the application? another words i need the application to know where it is running from. how do i detect that?
+2
A:
Like this:
Shared ReadOnly AppDirectory As String = _
Path.GetDirectoryName(New Uri(GetType(Program).Assembly.CodeBase).LocalPath)
SLaks
2010-04-09 18:20:05
what do u think of Hanin's answer?
I__
2010-04-09 18:22:10
It's much shorter, and will still work.
SLaks
2010-04-09 18:24:02
+2
A:
Application.ExecutablePath
that will tell you where your .exe is. Hope that helps.
Jim
2010-04-09 18:21:46
+3
A:
If your app is a Windows Forms app you can use the Application static class, as others have noted. For other kinds of applications, use reflection:
Dim a = System.Reflection.Assembly.GetEntryAssembly()
Dim location = a.Location
I had to do this the other day, works great.
magnifico
2010-04-09 18:22:24
+2
A:
If you put this code in your exe then it will give you the path of the exe.
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
gbogumil
2010-04-09 18:24:53