How can I get the application's path in a .NET console application?

where can i get a passport
passport application form
what do i need to get a passport
passport application locations
online application form
passport acceptance facility
how to get a green card
passport application post office

How do I find the application's path in a console application?

In Windows Forms, I can use Application.StartupPath to find the current path, but this doesn't seem to be available in a console application.

System.Reflection.Assembly.GetExecutingAssembly().Location1

Combine that with System.IO.Path.GetDirectoryName if all you want is the directory.

1As per Mr.Mindor's comment: System.Reflection.Assembly.GetExecutingAssembly().Location returns where the executing assembly is currently located, which may or may not be where the assembly is located when not executing. In the case of shadow copying assemblies, you will get a path in a temp directory. System.Reflection.Assembly.GetExecutingAssembly().CodeBase will return the 'permanent' path of the assembly.

How Long Does It Take to Become a U.S. Citizen?, How long does it take to become a US citizen in 2020? Find Job Applications Online now. Visit & Look for More Results!

You can use the following code to get the current application directory.

AppDomain.CurrentDomain.BaseDirectory

Apply online for a UK passport, But that's just the application processing wait time (see “Understanding USCIS Processing Times” below). Get Free Printable Application Forms Quick & Easy. Download Form Finder Free Now. Tax Forms. Citizenship Forms. Passport Forms. Application Forms. Printable PDF Forms.

You have two options for finding the directory of the application, which you choose will depend on your purpose.

// to get the location the assembly is executing from
//(not necessarily where the it normally resides on disk)
// in the case of the using shadow copies, for instance in NUnit tests, 
// this will be in a temp directory.
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;

//To get the location the assembly normally resides on disk or the install directory
string path = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;

//once you have the path you get the directory with:
var directory = System.IO.Path.GetDirectoryName(path);

How do I get a passport for the first time? Create a Residential Rental Application Form Step by Step in 5-10 Minutes.

Probably a bit late but this is worth a mention:

Environment.GetCommandLineArgs()[0];

Or more correctly to get just the directory path:

System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);

Edit:

Quite a few people have pointed out that GetCommandLineArgs is not guaranteed to return the program name. See The first word on the command line is the program name only by convention. The article does state that "Although extremely few Windows programs use this quirk (I am not aware of any myself)". So it is possible to 'spoof' GetCommandLineArgs, but we are talking about a console application. Console apps are usually quick and dirty. So this fits in with my KISS philosophy.

COVID-19 Update: Know Before You Apply For A U.S. Passport. If you are thinking about applying for or renewing a U.S. passport now for international travel,  Find Job Applications Online. Get High Level of Information!

For anyone interested in asp.net web apps. Here are my results of 3 different methods

protected void Application_Start(object sender, EventArgs e)
{
  string p1 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  string p2 = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
  string p3 = this.Server.MapPath("");
  Console.WriteLine("p1 = " + p1);
  Console.WriteLine("p2 = " + p2);
  Console.WriteLine("p3 = " + p3);
}

result

p1 = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a897dd66\ec73ff95\assembly\dl3\ff65202d\29daade3_5e84cc01
p2 = C:\inetpub\SBSPortal_staging\
p3 = C:\inetpub\SBSPortal_staging

the app is physically running from "C:\inetpub\SBSPortal_staging", so the first solution is definitely not appropriate for web apps.

Below you will find a general description of the application process. Before you apply, be sure that you meet all eligibility requirements. Check if you qualify for any  Open Enrollment is over. You can still get 2020 health insurance 2 ways: If you qualify for a Special Enrollment Period due to a life event like losing other coverage, getting married, or having a baby. If you qualify for Medicaid or the Children's Health Insurance Program (CHIP). You can apply for these programs any time.

If you are eligible, file Form I-485 - Application to Register Permanent you can move forward in applying for an immigrant visa (Green Card). When testing the application you authored yourself, you can find the Application Id in the generetated AppX\vs.appxrecipe file under RegisteredUserNmodeAppID node. E.g. c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App. My understanding is if I develop an app by myself, so I can control the authority and get application id in this way. but

How to apply, renew, or quickly get a passport. Also, learn how to get a passport for a child, check the status of your application, and how much  Tips and tricks you didn't know you could do with Google for on the go, at work and having fun.

With instant access to more than 800 colleges and universities around the world, the Common App is the most seamless way to manage the application process. The SS-5 form generally includes the following information: Full name. Full name at birth, including maiden name. Present mailing address. Age at last birthday. Date of birth. Place of birth (city, county, state) Father's full name. Mother's full name, including maiden name. Gender. Race as

Comments
  • Do you install .NET Framework on target (Client, Development) machine? if your answer is true; So, you can add a reference to System.Windows.Forms.dll and use Application.StartupPath! This is the best way if you want to drop away further future exceptions!
  • AppDomain.BaseDirectory is app directory. Be aware that application can behave different in VS env and Win env. But AppDomain should be same not as application.path but i hope that this is not only for IIS.
  • System.Reflection.Assembly.GetExecutingAssembly().Location returns where the executing assembly is currently located, which may or may not be where the assembly is located when not executing. In the case of shadow copying assemblies, you will get a path in a temp directory. System.Reflection.Assembly.GetExecutingAssembly().CodeBase will return the 'permenant' path of the assembly.
  • @SamGoldberg: That depend on how it is used: stackoverflow.com/q/1068420/391656 . Or you can ... new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath
  • GetExecutingAssembly returns assembly that contains the code that is currently executing. This may not necessarily be the console .exe assembly. It may be an assembly that has been loaded from a totally different location. You will have to use GetEntryAssembly! Also note that CodeBasemight not be set when the assembly is in the GAC. The better alternative is AppDomain.CurrentDomain.BaseDirectory.
  • Please write code in 4 spaces so it is comfortable to copy
  • @farosch: Application doesn't exist for console applications.
  • Don't use this. The BaseDirectory can be set at runtime. It is not guaranteed to be correct (like the accepted answer is).
  • +1 This is likely the answer you want as it compensates for shadow copying.
  • @usr What makes you think that BaseDirectory can be set at runtime? It only has a getter.
  • @bitbonk it can be set at appdomain creation time.
  • Isn't it that BaseDirectory can be changed in a *.lnk file, in the "Start in:" field?
  • Just wanted to say, obviously there are many more than 2 options by how many other choices are posted...
  • If whatever you're trying to do with said path doesn't support URI format, use var localDirectory = new Uri(directory).LocalPath;