C#FileBrowser对话框和写保护文件夹
用户应该创建一个文件夹,应用程序在其中创建xml文件。现在我面临的问题是这个文件夹是写保护的。因此,应用程序无法在此文件夹中写入xml文件。我不知道该怎么做C#FileBrowser对话框和写保护文件夹,c#,file,C#,File,用户应该创建一个文件夹,应用程序在其中创建xml文件。现在我面临的问题是这个文件夹是写保护的。因此,应用程序无法在此文件夹中写入xml文件。我不知道该怎么做 private void buttonCreate_Click(object sender, RoutedEventArgs e) { DialogResult result = folderElg.ShowDialog(); if (result == System.Windows.Forms.
private void buttonCreate_Click(object sender, RoutedEventArgs e)
{
DialogResult result = folderElg.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
textBoxPath.Text = folderElg.SelectedPath;
userConfigurePath = folderElg.SelectedPath;
}
XmlDocument config = new XmlDocument();
XmlNode myRoot;
myRoot = config.CreateElement("Tool");
config.AppendChild(myRoot);
config.Save(@userConfigurePath);
}
您不能写入受保护的文件夹。处理此问题的唯一方法是捕获异常并显示消息。例如:
try
{
config.Save(@userConfigurePath);
}
catch(Exception ex)
{
MessageBox.Show("Sorry there was en error with writing file. Try different location");
}
授予此文件夹的写入权限!问题是用户自己创建文件夹。他是否有可能创建具有写入权限的文件夹?他是如何创建此文件夹的?NTFS权限中有一个选项,您可以创建文件夹,但不能创建文件。private FolderBrowserDialog FolderEleg=new FolderBrowserDialog();还有一个问题是什么类型:
folderElg
是FileBrowserDialog
还是FolderBrowserDialog
?您应该使用FileBrowserDialog
,因为用户试图将文件另存为文件夹,是什么原因导致他出错