private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName); MessageBox.Show(sr.ReadToEnd()); sr.Close();
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionusing System; using Ionic.Zip; namespace Ionic.Zip.Examples { public class ReadZip { private static void Usage() { Console.WriteLine("usage:\n ReadZip2 <zipfile> "); Environment.Exit(1); } public static void Main(String[] args) { if (args.Length != 2) Usage(); if (!System.IO.File.Exists(args[0])) { Console.WriteLine("That zip file does not exist!\n"); Usage(); } try { // Specifying Console.Out here causes diagnostic msgs to be sent to the Console // In a WinForms or WPF or Web app, you could specify nothing, or an alternate // TextWriter to capture diagnostic messages. using (ZipFile zip = ZipFile.Read(args[0], System.Console.Out)) { // This call to ExtractAll() assumes: // - none of the entries are password-protected. // - want to extract all entries to current working directory // - none of the files in the zip already exist in the directory; // if they do, the method will throw. zip.ExtractAll(args[1]); } } catch (System.Exception ex1) { System.Console.Error.WriteLine("exception: " + ex1); } } } }
private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() = = System.Windows.Forms.DialogResult.OK) { System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName); MessageBox.Show(sr.ReadToEnd()); sr.Close(); public class ReadZip { private static void Usage() { Console.WriteLine("usage:\n ReadZip2 <zipfile> "); Environment.Exit(1); } public static void Main(String[] args) { if (args.Length != 2) Usage(); if (!System.IO.File.Exists(args[0])) { Console.WriteLine("That zip file does not exist!\n"); Usage(); } try { // Specifying Console.Out here causes diagnostic msgs to be sent to the Console // In a WinForms or WPF or Web app, you could specify nothing, or an alternate // TextWriter to capture diagnostic messages. using (ZipFile zip = ZipFile.Read(args[0], System.Console.Out)) { // This call to ExtractAll() assumes: // - none of the entries are password-protected. // - want to extract all entries to current working directory // - none of the files in the zip already exist in the directory; // if they do, the method will throw. zip.ExtractAll(args[1]); } } catch (System.Exception ex1) { System.Console.Error.WriteLine("exception: " + ex1); } } } } } }
private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName); MessageBox.Show(sr.ReadToEnd()); sr.Close();
private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName); MessageBox.Show(sr.ReadToEnd()); sr.Close();FileStream fileStreamIn = new FileStream (SrcFile, FileMode.Open, FileAccess.Read); ZipInputStream zipInStream = new ZipInputStream(fileStreamIn); ZipEntry entry = zipInStream.GetNextEntry(); FileStream fileStreamOut = new FileStream (DstFile + @"" + entry.Name, FileMode.Create, FileAccess.Write); int size; byte[] buffer = new byte; do { size = zipInStream.Read(buffer, 0, buffer.Length); fileStreamOut.Write(buffer, 0, size); } while (size > 0); zipInStream.Close(); fileStreamOut.Close(); fileStreamIn.Close();
using ICSharpCode.SharpZipLib.Zip;
private void buttonOpenFile_Click(object sender, EventArgs e) { //show a openfiledialog to select a file OpenFileDialog f = new OpenFileDialog(); f.Multiselect = false; if (f.ShowDialog() == DialogResult.OK) { textBoxFileName.Text = f.FileName; } } private void buttonOK_Click(object sender, EventArgs e) { if (textBoxFileName.Text != "") { if (radioButtonZip.Checked == true) { //start a new thread to zip it Thread th = new Thread(new ThreadStart(Zip)); th.Start(); } else { //start a new thread to unzip it Thread th = new Thread(new ThreadStart(UnZip)); th.Start(); } } }
private void button6_Click(object sender, EventArgs e) { if (textBoxFileName.Text != "") { Thread th = new Thread(new ThreadStart(Unzip)); th.Start(); } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using ICSharpCode.SharpZipLib.Zip; using System.IO; using System.Threading; namespace ZipTest { public partial class FormZip : Form { public FormZip() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { radioButtonZip.Checked = true; } private void buttonOpenFile_Click(object sender, EventArgs e) { //show a openfiledialog to select a file OpenFileDialog f = new OpenFileDialog(); f.Multiselect = false; if (f.ShowDialog() == DialogResult.OK) { textBoxFileName.Text = f.FileName; } } private void buttonOK_Click(object sender, EventArgs e) { if (textBoxFileName.Text != "") { if (radioButtonZip.Checked == true) { //start a new thread to zip it Thread th = new Thread(new ThreadStart(Zip)); th.Start(); } else { //start a new thread to unzip it Thread th = new Thread(new ThreadStart(UnZip)); th.Start(); } } } private void Zip() { toolStripStatusLabel1.Text = "Zipping..."; SetButtonOK(false); ZipHelp.Zip(textBoxFileName.Text, textBoxFileName.Text + ".zip", 4096); toolStripStatusLabel1.Text = "Done"; SetButtonOK(true); } private void UnZip() { toolStripStatusLabel1.Text = "UnZipping..."; SetButtonOK(false); ZipHelp.UnZip(textBoxFileName.Text, Path.GetDirectoryName(textBoxFileName.Text), 4096); toolStripStatusLabel1.Text = "Done"; SetButtonOK(true); } //the method to set button's state private void SetButtonOK(bool Enable) { if (buttonOK.InvokeRequired) buttonOK.Invoke(new SetEnableCallBack(SetButtonOK), new object[] { Enable }); else buttonOK.Enabled = Enable; } //delegate to call back delegate void SetEnableCallBack(bool Enable); } }
ZipInputStream s = new ZipInputStream(zipFilePath); // ici, je suppose que zipFilePath contient le chemin vers le fichier zip ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { string directoryName = Path.GetDirectoryName(theEntry.Name); string fileName = Path.GetFileName(theEntry.Name); string folder = "C:\\monDossier\"; // ici, c'est le répertoire qui va recevoir le contenu de ton zip // create directory Directory.CreateDirectory(folder +directoryName); if (fileName != String.Empty) { FileStream streamWriter = File.Create((folder + theEntry.Name)); int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } streamWriter.Close(); } } s.Close();