C#SaveFileDialog在特定的文件夹 [英] C# SaveFileDialog in specific folder
问题描述
我用 SaveFileDialog
来选择路径,我要保存的文件。我设置 InitialDirectory
到某个文件夹,但是我希望限制保存地点到该文件夹或该文件夹的子文件夹。 ?这是可能的。
SaveFileDialog对话框=新SaveFileDialog();
dialog.InitialDirectory =SomePath//这是我想成为的根文件夹
路径
没有是不可能的。
您不能直接设置这是一个物业上的 SaveFileDialog
。但是你可以尝试使用 FileOk
事件,以验证该文件是否在该目录中,否则取消该事件做!
dialog.FileOk + =
委托(对象发件人,发送CancelEventArgs E)
{
如果(dialog.FileName是错误的目录中)
{
e.Cancel = TRUE;
}
};
正如前面提到的,下一个最好的选择是建立自己的对话!
I use SaveFileDialog
to select the path where I want to save a file. I set InitialDirectory
to some folder, but I want to limit the save locations to that folder or subfolders of that folder. Is this possible?
SaveFileDialog dialog = new SaveFileDialog();
dialog.InitialDirectory = "SomePath"//this is the path that I want to be root folder
No it is not possible.
You can't directly set this as a Property on the SaveFileDialog
. But you can try to do it by using the FileOk
event to validate if the file is in that directory and otherwise cancel the event!
dialog.FileOk +=
delegate (object sender, CancelEventArgs e)
{
if (dialog.FileName is in wrong directory)
{
e.Cancel = true;
}
};
As mentioned, the next best option is to build your own Dialog!
这篇关于C#SaveFileDialog在特定的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!