我需要讀取文本文件並將其存儲到Db中。幾次訪問之後/讀取文件時,突然出現該消息該進程無法訪問該文件.NET
,因爲它正在使用由另一個進程的進程無法訪問該文件..
我已經檢查過幾次,但沒有其他過程附加到它。這裏是我的代碼..
// Storing the data in a data table
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("L_Date", typeof(DateTime)));
table.Columns.Add(new DataColumn("L_Time", typeof(TimeSpan)));
table.Columns.Add(new DataColumn("L_CardID", typeof(string)));
table.Columns.Add(new DataColumn("L_Status", typeof(string)));
table.Columns.Add(new DataColumn("L_Type", typeof(string)));
table.Columns.Add(new DataColumn("L_Catatan", typeof(string)));
int i2 = 0;
string[] content = System.IO.File.ReadAllLines(e.FullPath);
foreach (string line in content)
{
// some code
}
我的代碼人有什麼問題?
您是如何檢查的?其他訪問可能是暫時的 - 嘗試使用Process Monitor來觀察文件。 – Richard 2012-04-05 07:46:29
您是否在另一個編輯器中打開該文件?像MSWord一樣? – StuartLC 2012-04-05 07:48:29
是的...我使用PM來檢查它..沒有其他進程附加.. – 2012-04-05 07:54:57