为了账号安全,请及时绑定邮箱和手机立即绑定

c# 文件被谁使用?

c# 文件被谁使用?

C#
蛊毒传说 2022-06-12 15:10:26
我想要谷歌浏览器的历史链接,当我搜索时,我找到了谷歌浏览器的“历史”文件。但我无法读取“历史”文件,因为 Google Chrome 使用此“历史”文件。因此,首先我复制了“历史”文件,然后阅读了我复制的“历史”文件。它只工作了一次。因为当我第二次想要历史链接时,我得到“另一个进程使用的文件”错误(因为它无法删除)。private void button1_Click(object sender, EventArgs e){    listBox1.Items.Clear();     string userName = Environment.UserName;    string confilename = string.Format(@"Data Source=C:\Users\{0}\Desktop\History1827", userName);    string oldfilename = string.Format(@"C:\Users\{0}\AppData\Local\Google\Chrome\User Data\Default\History", userName);    string newfilename = string.Format(@"C:\Users\{0}\Desktop\History1827", userName);    File.Copy(oldfilename, newfilename); // I copy oldfile to newfile destination    using (SQLiteConnection connection = new SQLiteConnection(confilename))    {        connection.Open();        SQLiteCommand command1 = new SQLiteCommand();        command1.Connection = connection;        command1.CommandText = "Select * From urls";        SQLiteDataReader dr = command1.ExecuteReader();        string historylinks = "";        while (dr.Read())        {            // dr[0] = ID of Link , dr[1] = Link , dr[2] = Title of Link            historylinks = dr[0].ToString() + "\t--->" + dr[1].ToString(); // I get ID and Link from History file that i copied            listBox1.Items.Add(historylinks);        }        dr.Close();        connection.Close();    }    if (File.Exists(newfilename))    {        File.Delete(newfilename);        MessageBox.Show("Deleted");    }}错误 :File.Delete(newfilename);有效。所以,如果我不使用 SQLiteConnection,程序可以删除它复制的“历史”文件。谁使用了这个被复制的“历史”文件?我该如何解决?
查看完整描述

1 回答

?
梦里花落0921

TA贡献1772条经验 获得超6个赞

您可以尝试Process Explorer来查找打开文件句柄的应用程序。如果 Process Explorer 找不到,请使用Process Monitor跟踪哪个进程正在尝试访问该文件。



查看完整回答
反对 回复 2022-06-12
  • 1 回答
  • 0 关注
  • 143 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号