943,070 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 784
  • C# RSS
Jul 30th, 2010
0

Read files from a folder without using openfile dialog

Expand Post »
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.
C# Syntax (Toggle Plain Text)
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3.  
  4.  
  5. OpenFileDialog op = new OpenFileDialog();
  6. //DialogResult ok1 = dlgFolder.ShowDialog();
  7. //op.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
  8. List<string> lst2 = new List<string>();
  9. //if (ok1 != DialogResult.Cancel)
  10. if (op.ShowDialog() != DialogResult.Cancel)
  11. {
  12.  
  13. Title title1 = new Title();
  14. using (ZipFile zfile = new ZipFile())
  15. {
  16.  
  17. string path1 = op.FileName;
  18. string newpath = "c:/processed/Procc1";
  19. // using(var zf = Ionic.Zip.ZipFile.Read(path1))
  20.  
  21. using (ZipFile zip = ZipFile.Read(path1))
  22. {
  23.  
  24.  
  25. zip.ExtractAll(newpath);
  26.  
  27. StreamReader read = new StreamReader(newpath);
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
sadhawan is offline Offline
41 posts
since Jun 2010
Jul 30th, 2010
0
Re: Read files from a folder without using openfile dialog
Look in the System.IO namespace.
Especially System.IO.File and System.IO.Directory.
These are used to inspect the file system.
Last edited by nick.crane; Jul 30th, 2010 at 2:10 pm.
Reputation Points: 375
Solved Threads: 186
Veteran Poster
nick.crane is offline Offline
1,194 posts
since Feb 2010
Jul 30th, 2010
0
Re: Read files from a folder without using openfile dialog
Click to Expand / Collapse  Quote originally posted by sadhawan ...
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.
Reputation Points: 182
Solved Threads: 70
Posting Pro in Training
gusano79 is offline Offline
474 posts
since May 2004
Jul 30th, 2010
0
Re: Read files from a folder without using openfile dialog
Looking at the DetNetZip Library Examples you probably want to do something like this.
C# Syntax (Toggle Plain Text)
  1. // open zip file given in OpenFileDialog
  2. using (ZipFile zip = ZipFile.Read(op.FileName))
  3. {
  4. foreach (ZipEntry e in zip)
  5. {
  6. MemoryStream outputStream = new MemoryStream();
  7. e.Extract(outputStream); // write file contents to memory stream
  8. outputStream.Position = 0; // reset stream pointer to start
  9. // do what you want with the stream data.
  10. }
  11. }

[Edit] Thanks to both sadhawan and gusano79 for introducing me to these Zip libraries.
Last edited by nick.crane; Jul 30th, 2010 at 2:52 pm.
Reputation Points: 375
Solved Threads: 186
Veteran Poster
nick.crane is offline Offline
1,194 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: datagridview editable
Next Thread in C# Forum Timeline: how to inert all rows of datagridview c# into a table?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC