如何纠正问题'该进程无法归档'path \',该文件已被另一个进程使用 [英] how to rectify the isssue'the process cannot file 'path\' it is used by another process

查看:74
本文介绍了如何纠正问题'该进程无法归档'path \',该文件已被另一个进程使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我运行下面的代码,有时它''显示错误,如

该进程无法找到文件"\ path",该文件已被另一个进程使用"


谁能告诉我代码中的任何问题.




i run the below code, sometimes its'' showing error like

''the process cannot find file ''\path'' it is used by another process''


can anyone tell me any problem in my code.


// code for Zip a multiple files//


Crc32 crc = new Crc32();
string attach = AppDomain.CurrentDomain.BaseDirectory + "Documents/" + "Attachments.zip";

if (File.Exists(attach))
{
    File.Delete(attach);
}

ZipOutputStream s = new ZipOutputStream(File.Create(attach));
s.SetLevel(9); // 0 - store only to 9 - means best compression



string names = hidfield.Value;
string[] strNames = names.Split('','');

for (int i = 0; i < strNames.Length; i++)
{

    FileStream fs = File.OpenRead(AppDomain.CurrentDomain.BaseDirectory + "Documents/" + strNames[i]);

    byte[] buffer = new byte[fs.Length];
    fs.Read(buffer, 0, buffer.Length);

    ZipEntry entry = new ZipEntry(ZipEntry.CleanName("Documents/" + strNames[i]));
    entry.DateTime = DateTime.Now;
    entry.Comment = " ";
    entry.ZipFileIndex = i;
    entry.Size = fs.Length;
    fs.Close();
    crc.Reset();
    crc.Update(buffer);
    entry.Crc = crc.Value;
    s.PutNextEntry(entry);
    s.Write(buffer, 0, buffer.Length);
}

s.Finish();
s.Close();

推荐答案

为什么要一遍又一遍地问这个问题?哪一行给出了错误?如果只是有时发生,那么发生时又有什么不同呢?在调试时会发生这种情况吗,可能是在打开文件时停止了会话?仅在开发环境之外运行程序时会发生这种情况吗?有一个名为wholockme之类的应用程序,您可以在google上找到该应用程序,该程序将显示锁定文件的进程.这将帮助您判断它是当前实例还是旧实例仍然存在.

我看到您没有修复我指出的这段代码中的其他混乱情况. :(

哦-这是一个ASP.NET页面吗?我注意到您正在从隐藏字段中获取值.如果您将问题标记为ASP.NET,或者告诉我们它是ASP.NET,这将有所帮助,因此我们可以为您提供实际帮助.如果这是一个网页,那么您将在COURSE中间歇性地遇到此问题.如果您有两个页面实例试图写入同一文件,您认为会发生什么?

与其一遍又一遍地问相同的问题,不如先尝试着向他们提问,并实际上向我们提供我们需要帮助的信息.
Why are you asking this over and over again ? Which line gives the error ? If it only happens sometimes, what is different when it happens ? Does it happen when you''ve been debugging, might you have stopped the session while the file was open ? Does it happen when you are running the program only outside the dev environment ? There''s an app called wholockme or something, which you can find with google, which will show you what process is locking the file. That will help you tell if it''s the current instance, or if it''s a former instance that''s still alive.

I see you didn''t fix the other messes in this code that I pointed out to you. :(

Oh - is this an ASP.NET page ? I notice you''re grabbing values from a hidden field. It would help if you tagged your question as ASP.NET, or told us it was ASP.NET, so we could actually help you. If this is a webpage, then of COURSE you will get this issue intermittently. If you have two page instances trying to write to the same file, what do YOU think will happen ?

Instead of asking the same questions over and over, try asking them right in the first place, and actually giving us the information we need to help you.


这篇关于如何纠正问题'该进程无法归档'path \',该文件已被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆