我正在尝试开发一个应用程序,该应用程序允许我删除垂直配置文件区域中的文件和文件夹.我不断收到拒绝访问错误.这是我的代码 [英] I am try to develop an application that will allow me to delete files and folders in areas of a perticular profile. I keep getting an access deny error. Here is my code

查看:75
本文介绍了我正在尝试开发一个应用程序,该应用程序允许我删除垂直配置文件区域中的文件和文件夹.我不断收到拒绝访问错误.这是我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace IS_Application
{
    public partial class frmMain : Form
    {

        public frmMain()
        {
            InitializeComponent();
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            
             try
            {
                string user = textBox1.Text;
                DirectoryInfo username = new DirectoryInfo("C:\\Documents and Settings\\" + user);

                if (Directory.Exists(@"C:\Documents and Settings\" + user))

                File.Delete("C:\\Documents and Settings\\" + user + "\\Local Settings\\Temp\\");
                File.Delete("C:\\Documents and Settings\\" + user + "\\Local Settings\\Temp\\Temporary Internet Files\\");
                File.Delete("C:\\Documents and Settings\\" + user + "\\Application Data\\");

                //Directory.Delete("C:\\Documents and Settings\\" + user + "\\Local Settings\\Temp\\");
                //Directory.Delete("C:\\Documents and Settings\\" + user + "\\Local Settings\\Temp\\Temporary Internet Files\\");
            }
            catch (Exception)
            {
                throw;
            }
         }
     }
}

推荐答案

可能的原因1:
如果您尝试删除的文件是读取
,则会出现拒绝访问错误" 仅".如果您删除了只读属性,则文件将是
已删除.

可能的原因2:

文件正在使用中吗?听起来很明显,但是确实发生了.如果正在使用或打开它,请关闭文件和打开它的应用程序.例如,如果它是Word文档,请关闭Microsoft Word.

可能的原因3:
如果在应用程序中打开了该文件(然后关闭了该文件),但是该程序仍在运行,请尝试退出该程序. Windows将锁定文件,因为该应用程序尚未释放该文件.这并不总是Windows故障,而可能是程序故障.
Possible reason 1:
You will get an access denied error if the files you are tryingdelete are "Read
Only". If you get rid of the read only attribute and the files will be
deleted.

Possible reason 2:

Is the file in use? It sounds obvious but it happens. If it is being used or open, close the file and the application that opened it. For example, if it is a Word document, close Microsoft Word.

Possible reason 3:
If the file was opened in an application (and subsequently closed), but the program is still running, try quitting the program. Windows will lock a file because the application hasn''t yet released it. This is not always Windows fault and can be the fault of the program.


您不能删除Internet临时文件文件夹中的内容.该文件夹由Internet Explorer管理,必须使用IE的界面清除.
You cannot delete stuff in the Temporary Internet Files folder. That folder is managed by Internet Explorer and must be cleaned out using IE''s interface.


创建这样的应用程序没有任何意义.你是病毒作家吗?您不应该触摸其他用户拥有的文件.删除应用程序数据"是不安全的,因为某些应用程序使用该文件夹存储不应删除的永久数据.

您的应用程序将无法在Windows Vista和更高版本上运行,并且在某些XP系统上也会失败.

如果要进行清理以恢复一些空间,Windows已经提供了一个工具.用它. Windows可以更好地了解您为当前用户或任何用户存储临时文件的位置.

另外,删除帐户后,可以要求Windows执行清理.

最后,硬盘驱动器今天是如此便宜,以至于进行这种清理是没有意义的,除非使用Windows提供的工具每隔几个月进行一次清理(在Windows资源管理器中右键单击驱动器,然后选择属性",然后您就可以访问清洁选项).
It does not make sense to create such an application. Are you a virus writer. You should not touch files owned by other users. It is not safe to delete "Application data" as some application uses that folder for permanent data that should not be deleted.

You application will not works on Windows Vista and latter and will also fails on some XP system.

If you want to do some cleanup to recuperate some space, Windows already has a tool for that. Use it. Windows knows better that you where temporary files are stored either for the current user or any users.

Also when an account is deleted, it is possible to ask Windows to perform cleanup.

Finally, hard drives are so cheap these day that it does not make sense to do this kind of cleanup except maybe once every few months using tools provide by Windows (Right-click on a drive in Windows Explorer and select Properties then you will have access to options for cleaning).


这篇关于我正在尝试开发一个应用程序,该应用程序允许我删除垂直配置文件区域中的文件和文件夹.我不断收到拒绝访问错误.这是我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆