get path of directory c# code example

Example 1: 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 2: get execution directory c#

string logsDirectory = Path.Combine(Environment.CurrentDirectory, "logs");

Example 3: c# get path without filename

var fn = openFileDialogSapTable.FileName;
var currentPath = Path.GetFullPath( fn );
currentPath = Directory.GetParent(currentPath).FullName;