4

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:

Link1

Link2

Link3

Link4

Link5

Community
  • 1
  • 1
Michael Eakins
  • 4,149
  • 3
  • 35
  • 54
  • just curious, are these DLLs .NET assemblies that your application depends on? If so you shouldn't need to worry about this, The manifest should be taking care of this for you so long as you are including the assemblies in the build. Project Properties -> Publish -> Application Files -> Make sure you have the dependency assemblies marked to be deployed with your application. – J Cooper May 18 '11 at 20:06
  • You would think not but, my predecessor has a web designed that specifically tells the application where everything is. I am now converting this over to a WPF and I believe it will be much simpler if I can determine where the DLL's are. The DLL's are from 30 projects that my primary applicartion depends on. – Michael Eakins May 18 '11 at 20:21

2 Answers2

4

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

  • Takes in the first filepath
  • Determines the randomly generated foldername
  • finds the folder of the application based on that folder name(which contains your executables)

I think creating an extension method on type ApplicationDeployment would be fitting.

Hope that helps

Jose
  • 10,891
  • 19
  • 67
  • 89
0

This worked for me:

string exePath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName; string dir = Path.GetDirectoryName(exePath);

Rumata
  • 71
  • 4