954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Read files from a folder without using openfile dialog

Hi Guys,
I am unzipping a folder into a new folder and then wants to read all the files from the folder .My code is as follows.I dont want to create a folder but i cnt figure out a way to read all the files froma compressed folder and now when i create another folder i cnt read the files and i get error saying i do not have persmission to access teh folder.I have unchecked the read only preperty of the folder too.Can anyone help me with this.

private void button1_Click(object sender, EventArgs e)
        {


            OpenFileDialog op = new OpenFileDialog();
            //DialogResult ok1 = dlgFolder.ShowDialog();
            //op.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            List<string> lst2 = new List<string>();
            //if (ok1 != DialogResult.Cancel)
            if (op.ShowDialog() != DialogResult.Cancel)
            {

                Title title1 = new Title();
                using (ZipFile zfile = new ZipFile())
                {

                    string path1 = op.FileName;
                    string newpath = "c:/processed/Procc1";
                    // using(var zf = Ionic.Zip.ZipFile.Read(path1))

                    using (ZipFile zip = ZipFile.Read(path1))
                    {


                        zip.ExtractAll(newpath);
                       
                        StreamReader read = new StreamReader(newpath);
sadhawan
Light Poster
41 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

Look in the System.IO namespace.
Especially System.IO.File and System.IO.Directory.
These are used to inspect the file system.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 
I am unzipping a folder into a new folder and then wants to read all the files from the folder .My code is as follows.I dont want to create a folder but i cnt figure out a way to read all the files froma compressed folder and now when i create another folder i cnt read the files and i get error saying i do not have persmission to access teh folder.I have unchecked the read only preperty of the folder too.Can anyone help me with this.

If I read you right, you want to get at the contents of a ZIP file (compressed folder) without extracting them first. Yes? If so, you might look into using SharpZipLib .

gusano79
Posting Pro
519 posts since May 2004
Reputation Points: 182
Solved Threads: 77
 

Looking at the DetNetZip Library Examples you probably want to do something like this.

// open zip file given in OpenFileDialog
  using (ZipFile zip = ZipFile.Read(op.FileName))
  {
    foreach (ZipEntry e in zip)
    {
      MemoryStream outputStream = new MemoryStream();
      e.Extract(outputStream); // write file contents to memory stream
      outputStream.Position = 0; // reset stream pointer to start
      // do what you want with the stream data.
    }
  }


[Edit] Thanks to both sadhawan and gusano79 for introducing me to these Zip libraries.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You