我正在開發一個工具,它可以將.fbx模型和用戶輸入處理成單個文件以用於遊戲。當用戶按下「導入模型」按鈕的代碼如下,併爲每個按鈕類似:OpenFileDialog和UnauthorizedAccessException
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\Desktop
和C:\
驅動器本身導入文件,但它仍然會出現。我可以添加哪些代碼以訪問這些(和其他)文件夾?