亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 171 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號