Quantcast
Channel: DotNetZip Library
Viewing all 664 articles
Browse latest View live

Commented Issue: ZipFile.AddFile fails depending of the file size. [14087]

$
0
0
AddFile truncate the entry, and Extract trow an exception "bad read of entry test/MyFile.txt from compressed archive."
 
Debugging step by step sometimes work fine.
 
My code:
 
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim str As New String(" "c, 2490368)
IO.File.WriteAllText("C:\test\MyFile.txt", str)
End Sub
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using zip As New Ionic.Zip.ZipFile
zip.AddFile("C:\test\MyFile.txt")
zip.Save("C:\test\MyZip.zip")
End Using
End Sub
 
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Using zip As Ionic.Zip.ZipFile = Ionic.Zip.ZipFile.Read("C:\test\MyZip.zip")
For Each arch As Ionic.Zip.ZipEntry In zip
arch.Extract("C:\test\opened")
Next
End Using
End Sub
Comments: ** Comment from web user: mohammadforutan **

"zip.ParallelDeflateThreshold = -1" resolve my issue and save my day, thank you Mike


New Post: Limited support for other compression library

$
0
0
I was trying out other compression/decompression methods with ioniczip. Seems that only ZIP files supported. I couldn't even extract the BZip2 over sevenzip. Sure, ioniczip is powerfull but it cannot manage other decompression methods.

Will other decompression some day supported or is this project deprecated for real?

New Comment on "Getting-Started"

$
0
0
What exactly does number 8 mean? Maybe it means to include the DotNetZip License.txt file in any install packages we programmers produce that use the dll?

New Post: Create a service to archive files that have not been touched for 3 months and above

$
0
0
Anyone knows how to write a service for archiving files? Can please provide step by step instructions. Appreciated!

New Post: Problem with AlternateEncodingUsage

$
0
0
Hi,

There is a regression in the last Ionic.Zip binaries, when I zip a folder that contains files which contains not standard characters then it produce wrong zip files.

I use :
zip.AlternateEncoding = System.Text.Encoding.Unicode;
zip.AlternateEncodingUsage = Ionic.Zip.ZipOption.AsNecessary;

It works with version 1.9.1.5 with :
zip.UseUnicodeAsNecessary = true;

You can try with a folder name that contains a "È".

I'm also sad to see that this library is a bit dead :(

New Comment on "ASPNET Example 1"

$
0
0
@destryalhmns Simple examples using C# can currently be found at http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples . This page is showing a complete ASP.NET example. The clearest example which answers your question is "Add an entry, getting content from a string.", just replace `content` with your byte[], or you can use one of the other overloads of AddEntry. You can also check the reference at http://dotnetzip.herobo.com/DNZHelp/Index.html if you need more help.

New Comment on "ASPNET Example 1"

$
0
0
@destryalhmns Simple examples using C# can currently be found at http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=Examples . This page is showing a complete ASP.NET example. The clearest example which answers your question is "Add an entry, getting content from a string.", just replace `content` with your byte[], or you can use one of the other overloads of `AddEntry`. If you want to daisy chain the compressed result to a stream then change the `ZipFile` class to `ZipOutputStream`. You can also check the reference at http://dotnetzip.herobo.com/DNZHelp/Index.html if you need more help.

New Post: Defaulting the DotNetZip Help library to Visual Basic

$
0
0
In the DotNetZip help library (DotNetZipLib-v1.9.1.6.chm), I'd like to default the examples to Visual Basic, and I haven't located a way to do this. At every page I need to change to VB from C#. Is there an option for this?

New Comment on "CS-Examples"

$
0
0
Example using ZipOutputStream and ZipInputStream: public void TestZipStream() { byte[] startingData = new byte[102400], endingData = new byte[102400]; new Random().NextBytes(startingData); using (MemoryStream zipStream = new MemoryStream()) { //Zip data using (ZipOutputStream compressStream = new ZipOutputStream(zipStream, true)) { compressStream.PutNextEntry("A321"); compressStream.Write(startingData, 0, startingData.Length); } zipStream.Position = 0; //Unzip data using (ZipInputStream decompressStream = new Ionic.Zip.ZipInputStream(zipStream, true)) { decompressStream.GetNextEntry(); decompressStream.Read(endingData, 0, endingData.Length); } } }

New Post: Extremely Slow Performance Zipping a Single Large File

$
0
0
I'm trying to use the latest version of dotnetzip to zip up and password protect a single Sql Server backup file approximately 400 MB in size using the following code:

Using zip As New Ionic.Zip.ZipFile()
zip.Password = "Password"
zip.AddFile(filename)
zip.Save(filename + ".zip")
End Using

Nothing fancy. But it takes nearly forever for it to finish. I've played with various properties (setting ParallelDeflateThreshold to -1, trying different compression levels and methods, etc), but nothing seems to help.

Is anyone else having the same experience? Any ideas on how I can improve the performance?

New Post: Grouping Download Lists into Categories

$
0
0
I NEED HELP using dotnetzip and VB!

I need to separate the files to download and zip into four categories that are listed separately but the user will be able to select files from all categories for download. (I just want one download button instead of four).

Here's a link to my attempt to get this working: http://www.healthequity.com/NewSalesTest/checkbox/test4.aspx

For simplicity and since I'm a newbie, I'm trying to work out the kinks with just two categories. My code is below:

Dim width as String = "100%"
Public Sub Page_Load (ByVal sender As Object, ByVal e As System.EventArgs)
Try
    If Not ( Page.IsPostBack ) Then
        ' populate the dropdownlist
                    Dim hsaPath as  String= Server.MapPath("docs/hsa")
        Dim hraPath as  String= Server.MapPath("docs/hra")

                    Dim hsaFilenames As New List(Of String)(System.IO.Directory.GetFiles(hsaPath))
        Dim hraFilenames As New List(Of String)(System.IO.Directory.GetFiles(hraPath))


        Dim hsaDocs as List(Of String) = _
            hsaFilenames.ConvertAll (Function(s) s.Replace(hsaPath & "\", ""))

        Dim hraDocs as List(Of String) = _
            hraFilenames.ConvertAll (Function(s) s.Replace(hraPath & "\", ""))

        ErrorMessage.InnerHtml = ""

        hsaFileListView.DataSource = hsaDocs
        hraFileListView.DataSource = hraDocs
        hsaFileListView.DataBind()
        hraFileListView.DataBind()
    End If

Catch
    ' Ignored
End Try
End Sub



Public Sub btnGo_Click (ByVal sender As System.Object, ByVal e As System.EventArgs)
ErrorMessage.InnerHtml =""   ' debugging only

Dim HSAfilesToInclude as New System.Collections.Generic.List(Of String)()
Dim HRAfilesToInclude as New System.Collections.Generic.List(Of String)()

Dim hsaPath as String= Server.MapPath("docs/hsa")
Dim hraPath as String= Server.MapPath("docs/hra")

Dim HSAsource As DataKeyArray= hsaFileListView.DataKeys
Dim HRAsource As DataKeyArray= hraFileListView.DataKeys
For Each item As ListViewDataItem in hsaFileListView.Items
    Dim chkbox As CheckBox= CType(item.FindControl("HSAinclude"), CheckBox)
    Dim lbl As Label = CType(item.FindControl("HSAlabel"), Label)

    If Not (chkbox Is Nothing  OR  lbl Is Nothing) Then
        If (chkbox.Checked) Then
            ErrorMessage.InnerHtml = ErrorMessage.InnerHtml & _
                   String.Format("adding file: {0}<br/>", lbl.Text)
            HSAfilesToInclude.Add(System.IO.Path.Combine(hsaPath,lbl.Text))
            'filesToInclude.Concat(HSAfilesToInclude)
        End If
    End If
Next

For Each item As ListViewDataItem in hraFileListView.Items

   Dim chkbox As CheckBox= CType(item.FindControl("HRAinclude"), CheckBox)
   Dim lbl As Label = CType(item.FindControl("HRAlabel"), Label)

    If Not (chkbox Is Nothing  OR  lbl Is Nothing) Then
        If (chkbox.Checked) Then
            ErrorMessage.InnerHtml = ErrorMessage.InnerHtml & _
                    String.Format("adding file: {0}<br/>", lbl.Text)
            HRAfilesToInclude.Add(System.IO.Path.Combine(hraPath,lbl.Text))
            'filesToInclude.Concat(HRAfilesToInclude)
        End If
   End If
Next

Dim filesToInclude as New System.Collections.Generic.List(Of String)()
filesToInclude.Concat(HSAfilesToInclude)
filesToInclude.Concat(HRAfilesToInclude)

 If (filesToInclude.Count=0) Then
    ErrorMessage.InnerHtml = ErrorMessage.InnerHtml & "You did not select any files!"
Else
    Response.Clear
    Response.BufferOutput= false

    Dim c As System.Web.HttpContext = System.Web.HttpContext.Current
    Dim ReadmeText As String= String.Format("README.TXT\n\nHello!\n\n" & _
                                     "This is a zip file that was dynamically generated at {0}\n" & _
                                     "by an ASP.NET Page running on the machine named '{1}'.\n" & _
                                     "The server type is: {2}\n" & _
                                     System.DateTime.Now.ToString("G"), _
                                     System.Environment.MachineName, _
                                     c.Request.ServerVariables("SERVER_SOFTWARE"))
    Dim archiveName as String= String.Format("archive-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"))
    Response.ContentType = "application/zip"
    Response.AddHeader("Content-Disposition", "inline; filename=" & chr(34) & archiveName & chr(34))

    Dim tempfile As String = "c:\temp\" & archiveName
    Using zip as new ZipFile()
        ' the Readme.txt file will not be password-protected.
        zip.AddEntry("Readme.txt", ReadmeText, Encoding.Default)

        ' filesToInclude is a string[] or List<String>
        zip.AddFiles(filesToInclude, "files")

        ' save the zip to a filesystem file
        zip.Save(tempfile)
    End Using

    ' open and read the file, and copy it to Response.OutputStream
    Using fs as System.IO.FileStream = System.IO.File.OpenRead("c:\temp\" & archiveName)
        dim b(1024) as Byte
        dim n as New Int32
        n=-1
        While (n <> 0)
            n = fs.Read(b,0,b.Length)
            If (n <> 0)
                Response.OutputStream.Write(b,0,n)
            End If
        End While
    End Using
    Response.Close
    System.IO.File.Delete(tempfile)

End If
End Sub


</script>



<html>
<head><link rel="stylesheet" href="style/basic.css"></head><body>
<form id="Form" runat="server">

  <span class="SampleTitle"><b>Check the boxes to select the files, set a password if you like, then click the button to zip them up.</b></span>
  <br/>
  <br/>
  <span style="color:red" id="ErrorMessage" runat="server"/>
  <br/>
<h2>HSA</h2>
  <asp:ListView ID="hsaFileListView" runat="server">

    <LayoutTemplate>
      <table>
        <tr ID="itemPlaceholder" runat="server" />
      </table>
    </LayoutTemplate>

    <ItemTemplate>
      <tr>
        <td><asp:Checkbox ID="HSAinclude" runat="server"/></td>
        <td><asp:Label id="HSAlabel" runat="server" Text="<%# Container.DataItem %>" /></td>
      </tr>
    </ItemTemplate>

    <EmptyDataTemplate>
      <div>Nothing to see here...</div>
    </EmptyDataTemplate>

  </asp:ListView>
<h2>HRA</h2> 
  <asp:ListView ID="hraFileListView" runat="server">

    <LayoutTemplate>
      <table>
        <tr ID="itemPlaceholder" runat="server" />
      </table>
    </LayoutTemplate>

    <ItemTemplate>
      <tr>
        <td><asp:Checkbox ID="HRAinclude" runat="server"/></td>
        <td><asp:Label id="HRAlabel" runat="server" Text="<%# Container.DataItem %>" /></td>
      </tr>
    </ItemTemplate>

    <EmptyDataTemplate>
      <div>Nothing to see here...</div>
    </EmptyDataTemplate>

  </asp:ListView>

    <br/>
    <br/>
    <asp:Button id="btnGo" Text="Zip checked files" AutoPostBack OnClick="btnGo_Click" runat="server"/>

</form>
</body>

</html>

New Post: With Debug CLR Exceptions on, using wildcards results in "Invalid Characters in path"

$
0
0
Hi, I've been working on a small app that uses DotNetZip to handle packaged files. It works perfectly, but when I turned on all the exception debugging (as sort of a last pass before the app goes in for testing), I found that any use of wildcards returns a first-chance exception claiming that there are invalid characters in the path. For instance, this line:

ICollection<ZipEntry> myFiles = myZip.SelectEntries("(name != *.bla)");

throws the exception, whereas if I just simply remove the *, then no exception fires (although the results are not what I want - I need that wildcard):

ICollection<ZipEntry> myFiles = myZip.SelectEntries("(name != .bla)");

It's clearly not a problem with anything else, such as the path to the zip itself, since that second line fires no exception whatsoever.

I know it may be a moot point (since the app appears to be working perfectly fine despite the exceptions), but I'm not a fan of seeing exceptions like this firing. I've tried it with brackets, without brackets, with single quotes, without single quotes, and several other methods, and all results are the same - if the * is present, the call fires an exception (although the return value is exactly what I wanted).

Am I doing something wrong here?

Commented Issue: Wrong password exception for correct password [13668]

$
0
0
When I try to to read the content of the zipped file 562E0101.STM in 562E0101.ZIP I get exception "Bad password".
However, the password is correct. I am able to unpack with it when using WinRar, WinZip, Total Commander (unzip), even SharpZipLib works just fine (I suggest you take a look into their code).
 
Try to decompress the file attached with 6chars long password: 472713
 
The code I use:
using (ZipFile zip = ZipFile.Read(filePath))
{
zip.Password = password;
 
foreach (ZipEntry e in zip)
{
string entryName = Path.GetFileName(e.FileName);
string entryNameWithoutExtension = Path.GetFileNameWithoutExtension(entryName);
 
if (entryNameWithoutExtension.Equals(fileNameWithoutExtension))
{
e.Extract(tmpFolder, ExtractExistingFileAction.OverwriteSilently);
return Path.Combine(tmpFolder, e.FileName);
}
}
}
Comments: ** Comment from web user: erickwidya **

it's been old post but i have this strange behaviour too


when using dotnetzip i can't extract it, "Bad Password , the password did not match"
when i extract using windows explorer also the password did not match

but when i used 7zip, it can be extracted..

why?

thx,
erick

Commented Issue: Wrong password exception for correct password [13668]

$
0
0
When I try to to read the content of the zipped file 562E0101.STM in 562E0101.ZIP I get exception "Bad password".
However, the password is correct. I am able to unpack with it when using WinRar, WinZip, Total Commander (unzip), even SharpZipLib works just fine (I suggest you take a look into their code).
 
Try to decompress the file attached with 6chars long password: 472713
 
The code I use:
using (ZipFile zip = ZipFile.Read(filePath))
{
zip.Password = password;
 
foreach (ZipEntry e in zip)
{
string entryName = Path.GetFileName(e.FileName);
string entryNameWithoutExtension = Path.GetFileNameWithoutExtension(entryName);
 
if (entryNameWithoutExtension.Equals(fileNameWithoutExtension))
{
e.Extract(tmpFolder, ExtractExistingFileAction.OverwriteSilently);
return Path.Combine(tmpFolder, e.FileName);
}
}
}
Comments: ** Comment from web user: erickwidya **

sorry, forgot the password

the password = [PA219909PA]

New Post: how would one unzip a passworded zip with overwrite?

$
0
0
I see the unzipwithpassword and the unzipwithoverwrite = true but how to combine them so I can unzip a passworded file with overwrite?

New Post: DotNetZip SHA-2 Signed Key

$
0
0
Hello,

The DotNetZip .net library is signed with a SHA-1 strong named key. Is there a prebuilt DLL available with a SHA-2 strong named key? I do not see one prebuilt, or is the only alternative to build it ourselves? It is a business requirement that everything we have is built with SHA-2.

Thanks,
Robert

New Post: Create zip folder in amazon S3

$
0
0
0
down vote
favorite
I have to created a folder in the amazon S3. Now have to convert that folder in the zip file. I have used the DotNetZip Liberary to convert to the .zip file.

public void ConvertToZip(string directoryToZip, string zipFileName)
{
    try
    {

        using (client = DisposableAmazonClient())
        {
            var sourDir = new S3DirectoryInfo(client, bucket, directoryToZip);

            var destDir = new S3DirectoryInfo(client, bucket, CCUrlHelper.BackupRootFolderPhysicalPath);

            using (var zip = new ZipFile())
            {
                zip.AddDirectory(sourDir.FullName); // recurses subdirectories
                zip.Save(Path.Combine(destDir.FullName, zipFileName));
            }
        }

        logger.Fatal("Successfully converted to Zip.");
    }
    catch (Exception ex)
    {
        logger.Error("Error while converting to zip. Error : " + ex.Message);
    }
}

When I run the code it is showing the error "The given path's format is not supported."

Created Issue: BadReadException on byte[1179648] [16092]

$
0
0
```
public class Program
{
public static void Main(string[] args)
{
var source = new FileInfo("foo.txt");
using (var writer = source.CreateText())
writer.Write(new string('a', 1179648));

var target = new FileInfo(Path.ChangeExtension(source.FullName, "zip"));
var folder = new DirectoryInfo(Path.ChangeExtension(source.FullName, null));

if (target.Exists)
target.Delete();

if (folder.Exists)
folder.Delete(true);

using (var zip = new ZipFile(target.FullName))
{
zip.AddFile(source.FullName, string.Empty);
zip.Save();
}

using (var zip = new ZipFile(target.FullName))
zip.ExtractAll(folder.FullName);
}
}
```

```
Unhandled Exception: Ionic.Zip.BadReadException: bad read of entry foo.txt from compressed archive.
at Ionic.Zip.ZipEntry._CheckRead(Int32 nbytes)
at Ionic.Zip.ZipEntry.ExtractOne(Stream output)
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
at Ionic.Zip.ZipFile._InternalExtractAll(String path, Boolean overrideExtractExistingProperty)
at Ionic.Zip.ZipFile.ExtractAll(String path)
at ConsoleApplication1.Program.Main(String[] args) in C:\ZipDemo\ConsoleApplication1\ConsoleApplication1\Program.cs:line 32
```

Commented Issue: BadReadException on byte[1179648] [16092]

$
0
0
http://stackoverflow.com/questions/15337186/dotnetzip-badreadexception-on-extract


```
public class Program
{
public static void Main(string[] args)
{
var source = new FileInfo("foo.txt");
using (var writer = source.CreateText())
writer.Write(new string('a', 1179648));

var target = new FileInfo(Path.ChangeExtension(source.FullName, "zip"));
var folder = new DirectoryInfo(Path.ChangeExtension(source.FullName, null));

if (target.Exists)
target.Delete();

if (folder.Exists)
folder.Delete(true);

using (var zip = new ZipFile(target.FullName))
{
zip.AddFile(source.FullName, string.Empty);
zip.Save();
}

using (var zip = new ZipFile(target.FullName))
zip.ExtractAll(folder.FullName);
}
}
```

```
Unhandled Exception: Ionic.Zip.BadReadException: bad read of entry foo.txt from compressed archive.
at Ionic.Zip.ZipEntry._CheckRead(Int32 nbytes)
at Ionic.Zip.ZipEntry.ExtractOne(Stream output)
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
at Ionic.Zip.ZipFile._InternalExtractAll(String path, Boolean overrideExtractExistingProperty)
at Ionic.Zip.ZipFile.ExtractAll(String path)
at ConsoleApplication1.Program.Main(String[] args) in C:\ZipDemo\ConsoleApplication1\ConsoleApplication1\Program.cs:line 32
```
Comments: ** Comment from web user: Steam **

Was able to replicate this issue. Code works well with v1.9. Attached sample code with working version (using v1.9 of DotNetZip)

VS2012 used for testing.

New Post: Fails to install on Windows XP

$
0
0
I have tried running the msi installer on a Windows XP machine and it stops saying the 'DotNetZip Runtime cannot be installed on this computer. It is supported on Windows Server 2003, Windows Vista, or later.

Surely this should be checking to see whether the appropriate version of .Net is installed rather than the version of Windows.

I have an installer (based on NSIS) that needs to support Windows XP, Vista, 7 and 8. I would prefer to install using a standard DotNetZip install rather than repackaging with all the registration hassles for COM etc.
Viewing all 664 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>