Click here to Skip to main content
11,575,882 members (55,678 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Application
Hi, I want to get my application path after I install it, by C# code.
How can I get that? Should I use registry key?
Posted 4-Sep-11 19:42pm
Edited 4-Sep-11 19:45pm
Prerak Patel141.1K
v2
Comments
phoenix1167 at 10-Sep-11 1:05am
   
Thanks all, but none of these solutions solved my problem.I found the code,i used registry:

using Microsoft.Win32;

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Installer\Assemblies");
string regfilepath="";
if (key!=null) // Make sure there are Assemblies
{
foreach(string Keyname in key.GetSubKeyNames())
{
if (Keyname.IndexOf("YOUR_EXE_FILE.EXE")>0)
{
regfilepath=Keyname.Replace('|','\\');
break;
}
}
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

For the current assembly you can use:
System.Reflection.Assembly.GetExecutingAssembly().Location
See: Assembly.Location Property[^].

Depending on the situation (your application structure) you may want to find out the location of the entry assembly. In that case use:
System.Reflection.Assembly.GetEntryAssembly().Location
  Permalink  
Comments
SAKryukov at 5-Sep-11 3:04am
   
This is the only universal and reliable way I know. All other create problem in different cases. My 5.
A bit more detail in my solution -- please see.
--SA
Mika Wendelius at 5-Sep-11 3:07am
   
Thank you :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Here is the most universal way:

string exePath =
    System.IO.Path.GetDirectoryName(
       System.Reflection.Assembly.GetEntryAssembly().Location);

Other methods either require a library which you don't use (such as System.Windows.Forms) or depends on how the code is hosted (for example, using parameters of Main is not reliable).

—SA
  Permalink  
Comments
Mika Wendelius at 5-Sep-11 3:07am
   
Good addition, my 5
SAKryukov at 5-Sep-11 10:57am
   
Thank you, Mika.
--SA
Ali-19 at 6-Feb-12 5:45am
   
Thnx alot
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

string path= Application.StartupPath
for get your start up application folder location
  Permalink  
Comments
Ali-19 at 6-Feb-12 6:07am
   
The Problem I am facing is that I have created a folder in bin named Image, where I am saving images, but when I open dialog for selecting image so its location is changed and when i save it then its giving error, plz tell me how can i reset the default location

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 390
1 Dave Kreskowiak 204
2 F-ES Sitecore 135
3 OriginalGriff 125
4 Abhinav S 98
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 400
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 7 Sep 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100