我需要读取文本文件并将其存储到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