What is the simplest way to get the directory that a file is in? I'm using this to set a working directory.
string filename = @"C:\MyDirectory\MyFile.bat";
In this example, I should get "C:\MyDirectory".
You can use Path.GetDirectoryName and just pass in the filename.
Path.GetDirectoryName
MSDN Link