因此,我們有一個應用程序,用戶不斷丟失其工具欄,解決問題的唯一方法是刪除該用戶的應用程序數據中的文件夾。因此,我們寫了一個簡單的小程序,在這裏刪除這個文件夾就是我們在try catch
C#Directory.Delete投擲非法字符錯誤
System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.InternalCombine(String path1, String path2)
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)
at System.IO.Directory.Delete(String path, Boolean recursive)
at DeleteFolder.frnDeleteFolder.btnDelete_Click(Object sender, EventArgs e) in C:\Users\rmcintosh.K12.000\documents\visual studio 2010\Projects\DeleteFolder\DeleteFolder\frnDeleteFolder.cs:line 82
這裏得到的錯誤是我們使用刪除
string path = @"C:\Users\98532153\AppData\Roaming\DraftSight";
try
{
if (Directory.Exists(path)) {
Directory.Delete(path, true);
}
else
{
MessageBox.Show("Directory Does Not Exists");
}
}
catch (Exception ex)
{
richTextBox1.Text = ex.ToString();
}
我想指出的代碼這個工作發現只要主目錄是空的,但只要我添加任何文件子目錄,它會引發此錯誤。
檢查以確保路徑中沒有多餘的引號,並且路徑不以斜線結尾。 – Marko
刪除了路徑末尾的斜槓。 –
試試這個'string path = @「C:\ Users \ 98532153 \ AppData \ Roaming \ DraftSight」;' –