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?

Était-ce utile?

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"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top