You're probably looking for Path.GetDirectoryName(saveFileDialog.FileName)
.
Example:
string filePath = @"C:\MyDir\MySubDir\myfile.ext";
string directoryPath = Path.GetDirectoryName(filePath);
//directoryPath = "C:\MyDir\MySubDir"
Question
I would like to extract the selected path from Save dialog, excluding the file name.
The following code retrieves the full path + the file name with its extension.
placeToSaveDocument = Path.GetFullPath(saveFileDialog.FileName);
Please do not suggest to use Folder Browser Dialog instead, because I have a reason why not to use it.
Any ideas?
La solution
You're probably looking for Path.GetDirectoryName(saveFileDialog.FileName)
.
Example:
string filePath = @"C:\MyDir\MySubDir\myfile.ext";
string directoryPath = Path.GetDirectoryName(filePath);
//directoryPath = "C:\MyDir\MySubDir"