Hi,
Im my application, users will upload files to server. I want to impliment GZip to compress files.
But the compressed file is consuming more memory than actual file size.
What might be the problem?
Here is my code
Im my application, users will upload files to server. I want to impliment GZip to compress files.
But the compressed file is consuming more memory than actual file size.
What might be the problem?
Here is my code
Code:
protected void btnCompress_Click(object sender, EventArgs e)
{
if (fUpload.PostedFile == null)
{
lblMessage.Text = "No File Selected to Upload.";
}
string strName = Path.GetFileName(fUpload.PostedFile.FileName);
try
{
Stream oStream = fUpload.PostedFile.InputStream;
byte[] buffer = new byte[oStream.Length];
oStream.Read(buffer, 0, buffer.Length);
oStream.Close();
FileStream oFileStream = File.Create(Server.MapPath(Path.ChangeExtension(strName, "gz")));
GZipStream oGZipStream = new GZipStream(oFileStream, CompressionMode.Compress);oGZipStream.Write(buffer, 0, buffer.Length);
oGZipStream.Close();
lblMessage.Text = "\"" + strName + "\" was compressed & uploaded successfully.";
}
catch (Exception)
{
lblMessage.Text = "An Error Occured While Uploading File.";
}
}
Comment