Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# - How to Zip file on the Web Server?

C# - How to Zip file on the Web Server?

Scheduled Pinned Locked Moved C#
csharpsysadminhelptutorialquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HyVong
    wrote on last edited by
    #1

    Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*

    N A N H 4 Replies Last reply
    0
    • H HyVong

      Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Zip and Unzip from a C# program using J# runtime [^]

      H 1 Reply Last reply
      0
      • H HyVong

        Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Search for a library called SharpZipLib.dll on google

        1 Reply Last reply
        0
        • H HyVong

          Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          I have discussed this topic in this forum before, but check out #ziplib[^], it should do what you are looking for. - Nick Parker
          My Blog | My Articles

          1 Reply Last reply
          0
          • N Not Active

            Zip and Unzip from a C# program using J# runtime [^]

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            The ZIP classes in the J# runtime assemblies have problems where they don't create the right ZIP format all the time. Read Bug when using the java.util.zip classes to write zip files[^] for more information and links.

            Software Design Engineer Developer Division Sustained Engineering, Microsoft My Articles

            H 1 Reply Last reply
            0
            • H Heath Stewart

              The ZIP classes in the J# runtime assemblies have problems where they don't create the right ZIP format all the time. Read Bug when using the java.util.zip classes to write zip files[^] for more information and links.

              Software Design Engineer Developer Division Sustained Engineering, Microsoft My Articles

              H Offline
              H Offline
              HyVong
              wrote on last edited by
              #6

              using java.util.zip; using java.io; .. .. i created method to zip the file based on the codes have given. private void ZipFile(string fileName, string ExpType) { string extType = "zip"; string zipFileName = fileName + "." + extType; string soureFileName = fileName + "." + ExpType; // Output stream // ONCE IT RUNS THIS LINE, IT GIVES ME THE ERROR // SAYS 'ACCESS IS DENIED.' FileOutputStream fos = new FileOutputStream(zipFileName); // Tie to zip stream ZipOutputStream zos = new ZipOutputStream(fos); // Stream with source file FileInputStream fis = new FileInputStream(soureFileName); // It's our entry in zip ZipEntry ze = new ZipEntry(soureFileName); zos.putNextEntry(ze); sbyte[] buffer = new sbyte[1024]; int len; // Read and write until done while((len = fis.read(buffer)) >= 0) { zos.write(buffer, 0, len); } // Close everything zos.closeEntry(); fis.close(); zos.close(); fos.close(); } I have the folder that held the file temporary has full access for users. I don't know if i have to give the path for it to be able to zip too? Please help, i have no clue why it says access is denied. And is the code above correct? I haven't had a chance to test the whole codes since the first line had some error. hope to hear from everyone soon. thank you so much.:( *HyVong* oh and when i tried to delete the file after it's being zipped, but i can't, 'File' is an ambiguous reference, how do i delete the file after being zipped? File.Delete(Server.MapPath(@"~\import\\" + soureFileName)); Thanx so much for all your help.

              H 1 Reply Last reply
              0
              • H HyVong

                using java.util.zip; using java.io; .. .. i created method to zip the file based on the codes have given. private void ZipFile(string fileName, string ExpType) { string extType = "zip"; string zipFileName = fileName + "." + extType; string soureFileName = fileName + "." + ExpType; // Output stream // ONCE IT RUNS THIS LINE, IT GIVES ME THE ERROR // SAYS 'ACCESS IS DENIED.' FileOutputStream fos = new FileOutputStream(zipFileName); // Tie to zip stream ZipOutputStream zos = new ZipOutputStream(fos); // Stream with source file FileInputStream fis = new FileInputStream(soureFileName); // It's our entry in zip ZipEntry ze = new ZipEntry(soureFileName); zos.putNextEntry(ze); sbyte[] buffer = new sbyte[1024]; int len; // Read and write until done while((len = fis.read(buffer)) >= 0) { zos.write(buffer, 0, len); } // Close everything zos.closeEntry(); fis.close(); zos.close(); fos.close(); } I have the folder that held the file temporary has full access for users. I don't know if i have to give the path for it to be able to zip too? Please help, i have no clue why it says access is denied. And is the code above correct? I haven't had a chance to test the whole codes since the first line had some error. hope to hear from everyone soon. thank you so much.:( *HyVong* oh and when i tried to delete the file after it's being zipped, but i can't, 'File' is an ambiguous reference, how do i delete the file after being zipped? File.Delete(Server.MapPath(@"~\import\\" + soureFileName)); Thanx so much for all your help.

                H Offline
                H Offline
                HyVong
                wrote on last edited by
                #7

                actually i got this work, thank you so much for all your help i changed to System.IO.File.Delete(Server.MapPath(@"~\import\\" + soureFileName)); and the file did got zip, i gave it a path for specific folder

                // Stream with source file
                FileInputStream fis = new FileInputStream(Server.MapPath(@"~\import\\" + soureFileName));
                // Output stream
                FileOutputStream fos = new FileOutputStream(Server.MapPath(@"~\import\\" + zipFileName));
                // Tie to zip stream
                ZipOutputStream zos = new ZipOutputStream(fos);

                once again, thank you for all your help :) *HyVong*

                1 Reply Last reply
                0
                • H HyVong

                  Salut everyone, i have done lotz of seaching but i haven't find much. Anyhelp is greatly appreciate. I export a report into a csv file onto the webserver folder, now what i would like to do is zip that file that i just saved and allow the user to download it when they click a button. Anyone know what class .NET support for zipping a file? or any sample code on C# is great because i'm stuck here. merci beaucoup :);) *HyVong*

                  H Offline
                  H Offline
                  HyVong
                  wrote on last edited by
                  #8

                  it workssssssss yeeeeaaaahhhh :) thank you so much for all your help every one :) cheersssssss!! *HyVong*

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups