I want history links for Google Chrome and when i search, i found 'History' file of Google Chrome. But i can't read 'History' file because Google Chrome use this 'History' file. Therefore firstly i copy 'History' file and i read 'History' file that i copied.It worked but only once. Because when the second time i want history links, I get "File used by another Process" error(For it can't delete).
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");
}
}
Error : File.Delete(newfilename);
What did i do after that when i see this error?
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
//------ I DID NOT USE SQLİTECONNECTİON -----
//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");
}
}
It worked. So, if i don't use SQLiteConnection, Program can delete 'History' file that it copied .
Who use this 'History' file that was copied? How can i fix ?
Thank you.