Compress a file while upload the file is possible in

Total Post:341


C#  .NET  ASP.Net 
 1566  View(s)
Rate this:

here i browsing a file and elect and that i clicking button to transfer currently the file ought to compress and will not be save in nothing it is that if i transfer pdf it should be compress and save in a very folder as pdf format...please create this code on behalf of me...

protected void btnUpload_Click(object sender, EventArgs e)
       if (fileUpload.HasFile)
           string filename = Path.GetFileName(fileUpload.PostedFile.FileName);
           string path = Server.MapPath("~/SampleFiles/" + filename);
           lblTextMsg.Text = "File Uploaded Successfully.";

  1. Re: Compress a file while upload the file is possible in

    hi ankit,

    You can use GZipStream class.

    string fileToBeCompressed =//path of original file;
    string zipFilename = //path of zipped file;
    using (FileStream target = new FileStream(zipFilename, FileMode.Create,FileAccess.Write))
    using (GZipStream alg = new GZipStream(target, CompressionMode.Compress))
        byte[] data = File.ReadAllBytes(fileToBeCompressed);
        alg.Write(data, 0, data.Length);

      Modified On Apr-05-2018 05:54:00 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.