मैं निम्नलिखित कोड का उपयोग करने की कोशिश कर रहा हूं: मुझे दूषित ज़िप फ़ाइल मिलती है। क्यूं कर? फ़ाइल नाम ठीक प्रतीत होते हैं। शायद वे रिश्तेदार नाम नहीं हैं, और यह समस्या है?मैं रीयल टाइम में Response.Output पर फ्लाई और स्ट्रीम पर कैसे ज़िप करूं?
private void trySharpZipLib(ArrayList filesToInclude)
{
// Response header
Response.Clear();
Response.ClearHeaders();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.StatusCode = 200; // http://community.icsharpcode.net/forums/p/6946/20138.aspx
long zipSize = calculateZipSize(filesToInclude);
string contentValue =
string.Format("attachment; filename=moshe.zip;"
); // + " size={0}", zipSize);
Response.ContentType = "application/octet-stream"; //"application/zip";
Response.AddHeader("Content-Disposition", contentValue);
Response.Flush();
using (ZipOutputStream zipOutputStream = new ZipOutputStream(Response.OutputStream))
{
zipOutputStream.SetLevel(0);
foreach (string f in filesToInclude)
{
string filename = Path.Combine(Server.MapPath("."), f);
using (FileStream fs = File.OpenRead(filename))
{
ZipEntry entry =
new ZipEntry(ZipEntry.CleanName(filename))
{
DateTime = File.GetCreationTime(filename),
CompressionMethod = CompressionMethod.Stored,
Size = fs.Length
};
zipOutputStream.PutNextEntry(entry);
byte[] buffer = new byte[fs.Length];
// write to zipoutStream via buffer.
// The zipoutStream is directly connected to Response.Output (in the constructor)
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(fs, zipOutputStream, buffer);
Response.Flush(); // for immediate response to user
} // .. using file stream
}// .. each file
}
Response.Flush();
Response.End();
}
ASP.NET में, आप Response.BufferOutput = false की स्थापना करके करते हैं। – Cheeso