添加到 zip 文件/从 zip 文件中删除无法找到临时文件
我的程序允许用户将文件添加到 zip 文件中,一次上传一个。 第一次上传会创建一个 zip 文件,后续上传会添加到创建的文件中。 它还显示 zip 文件中所有文件的列表,并允许用户删除单个文件。
我使用 SharpZipLib,这在我的本地计算机上运行得很好,但是一旦我将其上传到服务器,它就开始在 CommitUpdate() 处崩溃
创建 zip 文件的原始上传很好,但是添加到 zip 文件或从中删除会给出:
找不到文件“W:\MyZipFile.zip.151.tmp”。
如果我将窗口放置一段时间,我可以在错误再次出现之前删除一个文件或添加一个文件。
我的添加文件方法:
ZipFile z = null;
if (System.IO.File.Exists(filePath + zipFilename))
z = new ZipFile(File.OpenRead(filePath + zipFilename));
else
z = ZipFile.Create(filePath + zipFilename);
z.BeginUpdate();
z.Add(filePath + filename, filename);
z.CommitUpdate();
z.Close();
My program lets users add files to a zip file one upload at a time. The first upload creates a zip file, and subsequent uploads add to the created file. It also displays a list of all the files in the zip file, and lets users delete individual files.
I use SharpZipLib and this works perfectly on my local computer, but once I uploaded it to the server it started crashing at CommitUpdate()
The original upload that creates the zip file is fine, but adding to the zip file, or deleting from it gives:
Could not find file 'W:\MyZipFile.zip.151.tmp'.
If I leave the window alone for a while, I can delete one file or add one file before the error starts again.
My add file method:
ZipFile z = null;
if (System.IO.File.Exists(filePath + zipFilename))
z = new ZipFile(File.OpenRead(filePath + zipFilename));
else
z = ZipFile.Create(filePath + zipFilename);
z.BeginUpdate();
z.Add(filePath + filename, filename);
z.CommitUpdate();
z.Close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想到了。 显示 zip 文件中的文件列表后,我忘记关闭 ZipFile。 这锁定了拉链,直到超时才让我编辑。
I figured it out. I forgot to close the ZipFile after I displayed the list of files in the zip file. That locked the zip and wouldn't let me edit until it timed out.
您需要确保运行应用程序的任何用户都具有 NTFS 权限,可以在 filepath 指定的文件夹中创建和修改文件
You need to make sure that whatever user the application is running as has NTFS permissions to create and modify files in the folder designated by filepath