문제

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?

도움이 되었습니까?

해결책

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"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top