locked
zip and unzip folder RRS feed

  • Question

  • when i debug it is showing (@"D:\ASI\Flood\out") access denied. can anyone tell me what is th problem and if there is any other easy way to unzip a folder

    java.io.

    FileOutputStream fos = new java.io.FileOutputStream(@"D:\ASI\Flood\out");

    java.util.zip.

    ZipOutputStream zos = new ZipOutputStream(fos);

    java.io.

    FileInputStream fis = new FileInputStream(@"D:\ASI\Flood\Production\test");

    java.util.zip.

    ZipEntry ze = new ZipEntry(@"D:\ASI\Flood\Production\test");

    zos.putNextEntry(ze);

     

    sbyte[] buffer = new sbyte[1024];

     

    int len;

     

    while ((len = fis.read(buffer)) >= 0)

    {

    zos.write(buffer, 0, len);

    }

    Tuesday, April 19, 2011 5:19 AM

Answers

  • Hi,

    As i have mentioned earlier that, in the String src  variable you need to give source zip file path.

    You have'nt  added zip file path.

    Your path must be like String src=@"D:\ASI\Flood\Download\sampleFile.zip";

     


    Kiran Saravade
    • Marked as answer by Paul Zhou Friday, April 22, 2011 5:16 AM
    Tuesday, April 19, 2011 6:30 AM
  •  

    Hi akki,

     

    Has your issue been resolved? Would you mind letting us know the result of the suggestions?

     

    Now I will mark an answer, you can mark others that you think to be so useful to your issue.

    You could “Unmark As Answer” if it doesn’t make sense.

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by akki_adhikari Friday, April 22, 2011 5:47 AM
    Friday, April 22, 2011 5:16 AM

All replies

  • Hi,

    I will provide you two solutions.

    1) First you need to refer free dll "Ionic.Zip" from Microsoft in your project.

    download location : http://dotnetzip.codeplex.com/releases/view/27890 

    Download "DotNetZipLib-Runtime-v1.9.zip", then refer "Ionic.Zip" dll from DotNetZip-v1.9 folder.

    Code snippet for unzip folder is as below:

     

    /// <summary>
        /// This method is used to extract zip file.
        /// </summary>
        /// <param name="src">Source zip file path.</param>
        /// <param name="target">Target extract location.</param>
        private void ExtractZip(string src, string target)
        {
          try
          {
            ZipFile zip = new ZipFile(src); zip.Password = "";
            zip.ExtractAll(target, ExtractExistingFileAction.OverwriteSilently);
            zip.Dispose();
            zip = null;
          }
          catch (Exception ex)
          {
            Trace.WriteLine("Extract fail for file : " + src);
            Trace.WriteLine(ex);
          }
        }
    

     

    2) May be you can refer to this link :

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b5bde5fa-f63a-41e0-8569-c75d2f61e76b

     


    Kiran Saravade
    • Proposed as answer by Ghouse Barq Thursday, April 21, 2011 9:43 AM
    Tuesday, April 19, 2011 5:56 AM
  • hi i used your code after downloading that file but it is not showing any result my code is below

     

     

    try

    {

     

    String src=@"D:\ASI\Flood\Download";

     

    String target = @"D:\ASI\Flood\Production";

    Ionic.Zip.

    ZipFile zip = new Ionic.Zip.ZipFile(src); zip.Password = "";

    zip.ExtractAll(target,

    ExtractExistingFileAction.OverwriteSilently);

    zip.Dispose();

    zip =

    null;

    }

     

    catch (Exception ex)

    {

     

    //Trace.WriteLine("Extract fail for file : " + src);

     

    //Trace.WriteLine(ex);

     

    MessageBox.Show(""+ex.Message);

    }

    Tuesday, April 19, 2011 6:26 AM
  • Hi,

    As i have mentioned earlier that, in the String src  variable you need to give source zip file path.

    You have'nt  added zip file path.

    Your path must be like String src=@"D:\ASI\Flood\Download\sampleFile.zip";

     


    Kiran Saravade
    • Marked as answer by Paul Zhou Friday, April 22, 2011 5:16 AM
    Tuesday, April 19, 2011 6:30 AM
  • thanks a lot man...........
    • Marked as answer by Paul Zhou Friday, April 22, 2011 5:16 AM
    • Unmarked as answer by Paul Zhou Friday, April 22, 2011 5:16 AM
    Thursday, April 21, 2011 8:42 AM
  • Hi akki_adhikari,

    If you feel that, i have answered your question then please do "Mark As Answer".

    Thanks.


    Kiran Saravade
    Friday, April 22, 2011 4:46 AM
  •  

    Hi akki,

     

    Has your issue been resolved? Would you mind letting us know the result of the suggestions?

     

    Now I will mark an answer, you can mark others that you think to be so useful to your issue.

    You could “Unmark As Answer” if it doesn’t make sense.

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by akki_adhikari Friday, April 22, 2011 5:47 AM
    Friday, April 22, 2011 5:16 AM