gpt4 book ai didi

c# - OpenFileDialog 和 UnauthorizedAccessException

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:16 26 4
gpt4 key购买 nike

我正在开发一种工具,可以将 .fbx 模型和用户输入处理成一个文件,以便在游戏中使用。用户按下“导入模型”按钮时的代码如下,每个按钮都类似:

private void E_ImportModelButton_Click_1(object sender, EventArgs e)
{
E_model = null; // byte array where model is stored
E_SelectedFileLabel.Text = "No Model Selected"; // label on form
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "FBX Model (.fbx)|*.fbx";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
// adjusts variables for game file
string s = Path.GetDirectoryName(ofd.FileName);
E_model = File.ReadAllBytes(s);
E_SelectedFileLabel.Text = "File Selected: " + ofd.FileName;
}
}

问题是,每当我单击确定时,都会发生 UnauthorizedAccessException。我尝试从 C:\Users\Owner\Downloads 以及 C:\Users\Owner\DesktopC:\ 自行驱动,但它仍然会发生。我可以向此代码添加什么以获得对这些(和其他)文件夹的访问权限?

最佳答案

您正在尝试通过旨在从文件中读取的方法从目录中读取:

string s = Path.GetDirectoryName(ofd.FileName);
E_model = File.ReadAllBytes(s);

替换为:

E_model = File.ReadAllBytes(ofd.FileName);

关于c# - OpenFileDialog 和 UnauthorizedAccessException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33404313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com