VarunJi
VarunJi

Reputation: 694

How to get folder path of Installed application, from Visual Studio 2012

Hi I have created 2 WPF application in PC. Lets suppose first is "OneApp" and another is "TwoApp". I have created this in Visual Studio 2012. I have installed OneApp from setup. Now I want to run "OneApp" by "TwoApp" application programmatically. So how can I find the path of "OneApp" application? Or if we can setup "OneApp" installation directory manually then that will also be great.

Edit:

I tried System.IO.Path.GetDirectoryName as suggested. But I am getting folder path as below

enter image description here

Can't I install in Program Files like other normal application?

Upvotes: 0

Views: 4976

Answers (3)

VarunJi
VarunJi

Reputation: 694

After all hit and try method. I just found a better solution for this problem in a blog. Link is

http://robindotnet.wordpress.com/2010/03/21/how-to-pass-arguments-to-an-offline-clickonce-application/

My code is to get the application: First get the short cut of that application, then open that shortcut will work fine. You can also see, how to send data to other application in above link.

StringBuilder sb = new StringBuilder();
sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
sb.Append("\\");
//publisher name is OneApp
sb.Append("OneApp");
sb.Append("\\");
//product name is OneApp
sb.Append("OneApp.appref-ms");
string shortcutPath = sb.ToString();
Console.WriteLine(shortcutPath);

//Start the One App installed application from shortcut
System.Diagnostics.Process.Start(shortcutPath);

Upvotes: 0

Sheridan
Sheridan

Reputation: 69959

You can generally ask the Assembly where it is on the hard drive. This should give you a path that starts with C:\ (if it is on the C drive obviously)... try this:

Assembly assembly = Assembly.GetExecutingAssembly();
Uri uri = new Uri(Path.GetDirectoryName(assembly.CodeBase));

In my development environment (Visual Studio), that gives me this:

C:/DevelopmentProjects/AppName/ProjectName/bin/Debug

eg. it is where the assembly is running from. On an installed application, it should tell you where that assembly is running from.

Upvotes: 3

apomene
apomene

Reputation: 14389

in wifomrs it is:

 Application.StartupPath

However that isnt the case for wpf , you are looking sth like:

Add System.IO reference:

using System.IO;

string baseDir=  System.AppDomain.CurrentDomain.BaseDirectory

or

string baseDir= System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)

Upvotes: 1

Related Questions