How to get folder path for ClickOnce application
I need to write a file in the same folder where a console ClickOnce .application
(executable file) resides. The folder where it launches from.
I tried using Application.StartupPath
& Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
but the path is pointing to a subfolder under c:\Documents & Settings
. How do I get the path where the .application
resides in?
To find the folder location, you can just run the app, open the task manager (CTRL-SHIFT-ESC), select the app and right-click|Open file location.
path is pointing to a subfolder under c:\Documents & Settings
That's right. ClickOnce applications
are installed under the profile of the user who installed them. Did you take the path that retrieving the info from the executing assembly gave you, and go check it out?
On windows Vista and Windows 7, you will find the ClickOnce cache here:
c:\users\username\AppData\Local\Apps\2.0\obfuscatedfoldername\obfuscatedfoldername
On Windows XP, you will find it here:
C:\Documents and Settings\username\LocalSettings\Apps\2.0\obfuscatedfoldername\obfuscatedfoldername
ApplicationDeployment.CurrentDeployment.ActivationUri might work
"A zero-length string if the TrustUrlParameters property in the deployment manifest is false, or if the user has supplied a UNC to open the deployment or has opened it locally. Otherwise, the return value is the full URL used to launch the application, including any parameters."
BUT what I think you really want is ApplicationDeployment.CurrentDeployment.DataDirectory which gives you a folder you can write data to. When you update the application anyways you'll lose what was in the original .exe folder, but you can migrate the data directory over to a new version of the app. Your app can write to this folder with whatever log files it has - and I'm pretty sure its guaranteed to be writable.