Frage

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?

War es hilfreich?

Lösung

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"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top