[英]OpenFileDialog / SaveFile Dialog Initial Folder
I've read through these questions and none of the solutions seem to work. 我已经阅读了这些问题,但似乎没有任何解决方案可行。 I can get it to work to C:\\ and work to the Users home folder but not the folder I've setup in documents for the user called 'Workspace Saves' Here are some code snips.
我可以让它工作到C:\\并工作到用户主文件夹,但不是我在文件中设置的文件夹,名为“工作区保存”的用户以下是一些代码剪辑。
Makes the folder if it doesn't exists. 如果文件夹不存在,则生成该文件夹。 This works fine...
这很好......
// Does Workspace Folder Check
Directory.CreateDirectory(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "/Workspace Saves");
The dialog part. 对话框部分。 This always opens in the user folder not the sub folder.
这始终在用户文件夹而不是子文件夹中打开。 tried it multiple ways.
尝试了多种方式。
// Opens Dialog Box
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
string path = (Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents") + "/Workspace Saves");
if (Directory.Exists(path))
{
saveFileDialog1.InitialDirectory = path;
}
else
{
saveFileDialog1.InitialDirectory = @"C:\";
}
saveFileDialog1.Filter = "Workspace Data File |*.wsda";
saveFileDialog1.Title = "Save current Workspace data.";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
而不是"/Workspace Saves"
,使用"\\\\Workspace Saves"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.