I have written a application with C#.But,I continually get an error message of "access denied" for "App D开发者_如何学运维ata" under my user profile (password protected user account).BTW,I'm using Win7.
Here is my code:
string path = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "//Programım//");
I would use System.IO.Path.Combine(...)
instead of string.Conact(...)
in this situation. Like this...
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Programım");
The result of path
in your original code might not be what you are actually expecting.
Once you are sure your path
value is correct then call System.IO.Directory.Delete(...)
like...
Directory.Delete(path, true);
If that still is not working, then there may be some other security permission problems with files in that directory, or with the directory itself. See the MSDN page for all of the exceptions that can be thrown from the Delete
method and the reasons why.
精彩评论