Karthi Keyan

Karthi Keyan

  • 1k
  • 755
  • 237.6k

Error while using ZipArchive.

Mar 28 2017 7:24 AM
Hi,
    The below is my code. i got error in  marked Lines. 
Error :
    
Severity Code Description Project File Line
Error CS1674 'ZipArchive': type used in a using statement must be implicitly convertible to 'System.IDisposable' 
 
Severity Code Description Project File Line
Error CS0246 The type or namespace name 'ZipArchiveEntry' could not be found (are you missing a using directive or an assembly reference?)
 I added the namespaces correctly but i got error. What mistake i did. kindly help me. Thanks in Advance.
 
using System;
using System.Windows.Forms;
using System.IO;
using System.IO.Compression;
namespace Zip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnclr_Click(object sender, EventArgs e)
{
txtsource.Text = "";
txtZip.Text = "";
}
private void btnprocess_Click(object sender, EventArgs e)
{
using (FileStream zipToOpen = new FileStream(txtZip.Text, FileMode.Open))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
{
   ZipArchiveEntry readmeEntry;
   DirectoryInfo d = new DirectoryInfo(txtsource.Text);
   FileInfo[] Files = d.GetFiles("*");
   foreach (FileInfo file in Files)
   {
      readmeEntry = archive.CreateEntryFromFile(txtsource.Text + "\\" + file.Name,       txtsource.Text + "/" + file.Name);
   }
}
}
}
}
}

Answers (4)