Click here to Skip to main content
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 20:42pm
Edited 4-Sep-11 20:45pm
Prerak Patel140.5K
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 Maciej Los 310
1 OriginalGriff 285
2 Afzaal Ahmad Zeeshan 200
3 Sergey Alexandrovich Kryukov 195
4 BillWoodruff 180
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 7 Sep 2011
Copyright © CodeProject, 1999-2014
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