對於我的WPF應用程序,我必須創建具有圖像文件的文件夾,例如:C:\ Pearl \ Src \ TEMP。稍後,當這些文件不需要時,我將以編程方式刪除這些文件夾。但我得到「進入路徑」被拒絕「。我也嘗試爲創建的臨時文件夾分配訪問權限,但沒有多大用處。訪問路徑被拒絕
using System.IO;
var activeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var dInfo = Directory.GetParent(Path.GetDirectoryName(activeDir);
var dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(@"ATSDEV\ABCD", FileSystemRights.DeleteSubdirectoriesAndFiles, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity); // Set the new access settings.
var ImageDir = Path.Combine(dInfo.ToString(), "TEMP");
System.IO.Directory.CreateDirectory(ImageDir, dSecurity);
你能後拋出異常的確切的行? 似乎錯誤是你得到路徑名的方式 – LoSciamano 2011-06-07 16:16:40
你確定你還沒有任何句柄(文件)仍然打開嗎? – Polyfun 2011-06-07 16:19:50
它被稱爲** [UAC](http://stackoverflow.com/questions/5210575/does-windows-7-have-the-same-problem-as-vista/5210642#5210642)**。你根本不應該寫這個目錄。幸運的是,還有其他選擇。 – 2011-06-07 16:23:09