接
ZIP文件上传到服务端,客户端下载后解压时创建文件读取流数据和服务端保存不一样的时候会丢失dll的版本信息,导致dll无法加载;dll之间的引用版本信息是绑定的,没有版本信息会出现引用错误。
以下是优化过的代码
服务端保存文件方法:
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int uploadFileLength = 0;
string saveFullPath = Server.MapPath("~/Plugins/") + "\\" + Request.QueryString["Filename"].ToString();
using (FileStream fs = new FileStream(saveFullPath, FileMode.Create))
{
while (uploadFileLength < Request.InputStream.Length)
{
//从输入流放进缓冲区
int bytes = Request.InputStream.Read(buffer, 0, bufferSize);
fs.Write(buffer, 0, bytes);
fs.Flush(); // 字节写入文件流
uploadFileLength += bytes;// 更新大小
}
fs.Close();
}
uploadFileLength = 0;
客户端解压保存文件方法:
fs = File.Create(fileName);
int size = 1024;
byte[] data = new byte[size];
while (true)
{
size = zipStream.Read(data, 0, data.Length);
if (size > 0)
fs.Write(data, 0, size);
else
break;
}
本文探讨了ZIP文件在上传至服务端并由客户端解压时出现DLL版本信息丢失的问题,该问题会导致DLL加载失败。文章提供了经过优化的服务端文件保存方法及客户端解压保存文件的方法。
1116

被折叠的 条评论
为什么被折叠?



