How to get the path to the program

I use

string path = AppDomain.CurrentDomain.BaseDirectory;to get my path to the application, but it gives something like

C:\Projects\XYZ\ABC\bin\Debug

I do not want bin \ Debug. Is there any way to achieve this?

+4
source share
5 answers

The AppDomain.CurrentDomain.BaseDirectory property gets the base directory that the assembly recognizer uses to build assemblies.

Thus, it works 100%, as it should be. If you want to create an application, cut it out and paste it to another location in another folder or drive. These changes will be reflected in this property.

In addition, you mentioned that you do not need this part bin\Debug, so you want to do this? Please be specific.

+11
source

( ):

string path = Application.ExecutablePath;
+2

IDE , . IDE - , .

: , IDE , $PROJECT_DIR\bin\Debug.

+1
string LPath;
string Location = AppDomain.CurrentDomain.BaseDirectory + "Reports\\rptEmployInfoStat.rpt";
int index;
index = Location.IndexOf("bin");
if (index > 0)
{
     LPath = Location.Remove(index, 10);
}
else
{
     LPath = Location;
}
rd.Load(@LPath);
+1

, , , :

string dir = System.IO.Directory.GetCurrentDirectory().Replace("\\bin\\Debug", "");
0

All Articles