Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:27:14+00:00 2026-06-15T03:27:14+00:00

Possible Duplicate: How do I find out what directory my console app is running

  • 0

Possible Duplicate:
How do I find out what directory my console app is running in with C#?

How to get current working directory of a console that runs a program so I could resolve relative paths passed as program args?

Lets say I’ve put my program here: c:\tools\program.exe
But I’m invoking it from various places. Lets say I’m here: C:\Users\Me\Documents\ and I run this command program.exe --src=somefile.txt --dest=subdir\otherfile.txt

Environment.CurrentDirectory and System.Reflection.Assembly.GetExecutingAssembly().Location will return c:\tools but I would like to be able to resolve somefile.txt and subdir\oterfile.txt paths that are relative to C:\Users\Me\Documents\.

====== UPDATE ======

Thank you for your help. It seems that Environment.CurrentDirectory works as expected. It turned out that in my case the problem was caused by Xenocode’s Postbuild tool (now called Spoon Virtual Application Studio) that I occasionally use to “pack” all program’s files (including dlls, config, etc.) into one executable. It’s very handy, but in this case the “virtualization” feature messed up my program’s Environment variables. I’ve managed to solve that issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:27:16+00:00Added an answer on June 15, 2026 at 3:27 am

    Environment.CurrentDirectory gives you the Current Working Directory

    Let me show a simple example:

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Startup: " + Environment.CurrentDirectory);
            Environment.CurrentDirectory = @"D:\temp";
            Console.WriteLine("After:" + Environment.CurrentDirectory);
        }
    }
    

    Now I create two folders named D:\temp and D:\temp2
    I put the executable in D:\temp
    Open a command prompt and set the current working directory with cd D:\temp2
    From that directory I run ..\temp\mytestapp.exe

    the output is

    Startup: D:\temp2
    After: D:\temp
    

    As a curiosity:

    this was the documentation for Environment.CurrentDirectory in Net 1.1

    Gets and sets the fully qualified path of the current directory; that
    is, the directory from which this process starts.

    and this is the documentation in NET 4.0

    Gets or sets the fully qualified path of the current working
    directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to find out where a function is defined? get filename of
Possible Duplicate: How to find out where a function is defined? I am working
Possible Duplicate: On iPhone: Find out what song is currently playing? (in the iPod
Possible Duplicate: JSON Parsing in Android As I find out I need to use
Possible Duplicate: JavaScript: How to find out when images are turned off in browser?
Possible Duplicate: Automatic counter in Ruby for each? I want to find out the
Possible Duplicate: How to find out where a function is defined? included php file
Possible Duplicate: Learning to write a compiler I looked around trying to find out
Possible Duplicate: In Ruby, how do I find out if a string is not
Possible Duplicate: How to find out where a function is defined? I wanna know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.