I have been investigating this for several hours. I have found numerous links, including several here on SO which claim to show how to find the startup path, or the application directory. All of the solutions suggested return a location:
C:\Users\<my user name>\AppData\Local\Apps\2.0\XO8PWL8B.5HH\1GZX7M0H.N1J\<temp location>\
When my WPF xbap is run from a remote location. I need to determine the actual folder of the remote location.
I am deploying this to an internal server ABCDEF, so in order to run this application I am entering:
\\ABCDEF\myApp.xbap
I want to programmatically determine the server and folder. My reason for this is that each time you publish a WPF with "automatically increment revision with each publish
" turned on. The folder where additional DLL's are located changes, additional programs that this program depends on.
I want to be able to dynamically determine the correct folder to look at.
I have tried:
'Dim path As String = Reflection.Assembly.GetEntryAssembly().Location
'Dim Path As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
'System.IO.Path.GetDirectoryName(System.Reflection. Assembly.GetExecutingAssembly.Location)
'application.StartupPath
All of which did not work.
These links suggested many of the methods I have tried:
I think this will steer you in the right direction. Since it sounds like you're deploying via ClickOnce you should get the information you need here:
System.Deployment.Application.ApplicationDeployment.CurrentDeployment
this class can be found in the System.Deployment.dll
Unfortunately the CurrentDeployment
object doesn't actually tell you where the application lives so you have to do some more work :(
if you call this:
var datadir = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory
you'll get something like this(for the datadirectory)
C:\Users\Administrator\AppData\Local\Apps\2.0\Data\BVPTZA5G.3AC\WC2WBZ92.D96\ expe..tion_ba14dd6bedbd6876_0000.0009_7919ca38a4e51341\Data\1.0.0.0
from there you need to get the folder name of the bold folder above because the application lives here(not the data directory):
C:\Users\Administrator\AppData\Local\Apps\2.0\RCVHD71Y.7CQ\BC42YMHT.ZQ0\ expe..tion_ba14dd6bedbd6876_0000.0009_7919ca38a4e51341
So I would create a function that
I think creating an extension method on type ApplicationDeployment would be fitting.
Hope that helps