我编写了一个简单的程序,试图删除(通过File.Delete)ProgramData下目录中的文件。
即使我的帐户具有管理权限,我也会得到'System.UnauthorizedAccessException'和我的程序关闭而不删除文件。
有什么方法可以删除文件吗?
提前谢谢任何帮助。
- Michael Bate
解决方案
嗨MichaelBate,
感谢您发布此处
对于您的问题,您要删除的文件是什么?
通常,文件。 Delete()方法可以很好地工作,除了文件是特殊的。请尝试下面的代码。
File.SetAttributes(filePath,FileAttributes.Normal); File.Delete( filePath );最好的问候,
温迪
I wrote a simple program that attempts to delete (via File.Delete) a file in a directory underneath ProgramData.
Even though my account has administrative privileges I get the 'System.UnauthorizedAccessException' and my program closes without deleting the file.
Is there any way that I can delete the file?
Thanks in advance for any help.
- Michael Bate
解决方案Hi MichaelBate,
Thank you for posting here
For your question, what is the file you want to delete?
Normally, File.Delete () method would work well except the file is special. Please try the code below.
File.SetAttributes(filePath, FileAttributes.Normal); File.Delete(filePath);Best Regards,
Wendy
更多推荐
具有管理权限的'System.UnauthorizedAccessException'
发布评论