该文件由其他一些进程使用 [英] The file is used by some other process
本文介绍了该文件由其他一些进程使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我试图通过流读取器读取但它说它无法访问该文件,因为它被其他一些进程使用该文件在我的c上开车,我不打开它是我的方法
当我调试我看到的记录填充
public int RunConversion()
{
string [] hl7Files = Directory.GetFiles(inputFilePath);
// List< string> list = new List< string>();
string line = string 跨度> .Empty;
foreach ( string hl7 in hl7Files)
{
try
{
使用(StreamReader sr = new StreamReader(hl7))
{
DataRow dtRow = demoTable.NewRow();
// int count = 0;
while (!sr.EndOfStream)
{
line = sr.ReadLine();
string [] lineData = line.Split(' |'跨度>);
for ( int i = 0 ; i < lineData.Length - 1 ; i ++)
{
demoTable.Rows.Add(dtRow); \\ 当 debug我没有看到任何值 when 我为行设置了一个监视窗口。
dtRow = demoTable.NewRow();
} // while
} // 使用
if ( File.Exists(hl7))
{
File.Copy(hl7,Path.Combine(archiveFilePath,Path.GetFileName(hl7)+ ) 。已处理), true );
File.Delete(hl7);
}
}
catch (例外情况)
{
if (File.Exists(hl7))
{
File.Copy(hl7,hl7 + 。失败, true );
File.Delete(hl7);
}
StringBuilder message = new StringBuilder();
message.Append( line = + line +出错 处理文件 + hl7)时;
message.Append( \ nError Details:\ n );
message.Append(ex.Message.ToString());
message.Append( \ nNo人口统计文件生成!!! \ n 跨度>);
throw new 异常(message.ToString());
}
}
return 1 跨度>;
}
任何人都可以帮助我。
谢谢
解决方案
请看我过去的答案,它可以帮到你:另一个进程异常使用的文件 [ ^ ]。
-SA
Hi
I am trying to read through a streamreader but it says it cant access the file because it is used by some other process the file is on my c drive and I am not opening it below is my method
when I debug I am seeing the records populating
public int RunConversion()
{
string[] hl7Files = Directory.GetFiles(inputFilePath);
// List<string> list = new List<string>();
string line = string.Empty;
foreach (string hl7 in hl7Files)
{
try
{
using (StreamReader sr = new StreamReader(hl7))
{
DataRow dtRow = demoTable.NewRow();
//int count = 0;
while (!sr.EndOfStream)
{
line = sr.ReadLine();
string[] lineData = line.Split('|');
for (int i = 0; i < lineData.Length - 1; i++)
{
demoTable.Rows.Add(dtRow);\\ when debug I dont see any values when I put a watch window for Rows.
dtRow = demoTable.NewRow();
}//while
}//using
if (File.Exists(hl7))
{
File.Copy(hl7, Path.Combine(archiveFilePath, Path.GetFileName(hl7) + ".Processed"), true);
File.Delete(hl7);
}
}
catch (Exception ex)
{
if (File.Exists(hl7))
{
File.Copy(hl7, hl7 + ".Failed", true);
File.Delete(hl7);
}
StringBuilder message = new StringBuilder();
message.Append("Error occurred in line = " + line + " when processing file " + hl7);
message.Append("\nError Details:\n");
message.Append(ex.Message.ToString());
message.Append("\nNo Demographics File Generated!!!\n");
throw new Exception(message.ToString());
}
}
return 1;
}
can anybody help me.
Thanks
解决方案
Please see my past answer, it can help you: File used by another process exception[^].
—SA
这篇关于该文件由其他一些进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文