c# get current running directory code example

Example 1: c# get current directory

string currentDir = System.IO.Directory.GetCurrentDirectory();
//returns the current directory of the application when executing

Example 2: get working directory c#

var DDIR = System.IO.Directory.GetCurrentDirectory();
var WorkingDirectory = "";
int index = DDIR.IndexOf(@"\");
if (index > 0)
	WorkingDirectory = DDIR.Substring(0, index) + @"\";

Example 3: c# get script directory

System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);