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?
In runtime, you can use:
Application.StartupPath
Application.ExecutablePath
that will tell you where your .exe is. Hope that helps.
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.
Like this:
Shared ReadOnly AppDirectory As String = _
Path.GetDirectoryName(New Uri(GetType(Program).Assembly.CodeBase).LocalPath)
You can have a look at
Application.ExecutablePath Property
or
AppDomain.BaseDirectory Property
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)
Related
I want to access the path of the folder that my published application has been run from.
Everything I can find says use Application.StartupPath(), but this doesn't work.
I wrote a simple program to display these, published to a single standalone file and then ran it from the directory C:\Users\jerem\Downloads\split.
This is what i got:
Application.StartupPath = "C:\Users\jerem\AppData\Local\Temp\.net\getlaunchdir\jvi1ji54.zau\"
Application.ExecutablePath = "C:\Users\jerem\AppData\Local\Temp\.net\getlaunchdir\jvi1ji54.zau\getlaunchdir.dll"
It seems that running the .exe file creates a temp folder with a load of files in it that are then run. Fine, but it returns the "wrong" results for StartupPath - i.e. not what I want.
How do I fix this?
Thanks
** image of publish settings added as requested by Caius Jard.
picture of publish settings
I'm not sure how you get your image showing application.startuppath as C:\temp\ - that looks like a debug mode shot and my problem only occurs while running the published program.
I suspect you published it with ClickOnce? If you publish it with Folder, it ought to behave as you expect
And when run:
Possibly might be what you are looking for:
Private uriBuilder As New UriBuilder(Reflection.Assembly.GetExecutingAssembly().CodeBase)
Public FullAssemblyPath As String = Uri.UnescapeDataString(uriBuilder.Path)
Public ExeDirectory As String = IO.Path.GetDirectoryName(FullAssemblyPath)
As windows store apps runs in so called sand-boxed environment,I decided to use folderpicker to get access to files.
I wanted to show the user his %localappdata% folder when file/folder picker is launched(C:\Users\Admin\AppData\Local)
I couldn't find a way to do this or to set any custom location ("C\testFolder") instead of through setting predefined PickerLocationId enumeration.
Any help would be really appreciated.
It is not possible. WinRT doesn't have any provision to set ANY folder as SuggestedStartLocation.
I am working on a visual basic project to download files from the internet.
Well i have a Url textbox, directory textbox, and a download button.
And YES i have done some research and i know it is something like...
wclient.DownloadFile(Url.Text,Directory.text)
but for some reason "wclient" doesn't work it says its "not defined"..?
What else should i use or how should i declare it? Should i import something?
Can You help me out?
Thanks in advance!
As simple as that:
Dim wClient As New WebClient
wClient.DownloadFile("RemoteAdress", "LocalFilePath")
RemoteAdress something like "http://example.com/sample.gif"
LocalFilePath something like "C:\Users\Username\Desktop\sample.gif"
Just make sure RemoteAdress is correct, and be aware that your application must have write access to LocalFilePath.
I'm trying to write a little Jukebox application in VB Forms, and I need the pathnames of the sound files (\bin\Tracks\"Insert Name Here") to be relative instead of absolute, so that it may work on a different computer to mine. At the moment, I am testing with the simple Soundplayer class, and the single line of code to play a song is this:
My.Computer.Audio.Play("\bin\Tracks\" & txtCurrentlyPlaying.Text)
It works when, instead of \bin\Tracks\, I put the full pathname (C:\Documents And Settings etc.), but not when I try a relative path such as this. Can anybody help?
Thank you for your time.
Nick
Try Path.Combine(Environment.CurrentDirectory, txtCurrentlyPlaying.Text)
I want to Set Culture for Windows Service that I developed. Can someone recommend me a good read for or how to go about it.
So far I have I Tried to do the Following OnStart()
Dim oCultureInfo as CultureInfo = New CultureInfo("tr-TR")
System.Threading.Thread.CurrentThread.Culture = oCultureInfo
System.Threading.Thread.CurrentThread.UICulture = oCultureInfo
After doing so I still see that My culture is US English.
Go to your setup which will be in the same solution.
Right click on it and select ADD->PROJECT OUTPUT--> a window will appear.
Select Project- your localization project then select from below localized resource.
Just click ok. you will see one file is added to setup project.
Just compile and install it will work fine.