How can i use in my project with SevenZipSharp to compress all the files in the List<> ?


thats code of form1 :

 

 

  using system;  using system.collections.generic;  using system.componentmodel;  using system.data;  using system.drawing;  using system.linq;  using system.text;  using system.windows.forms;  using system.io;  using system.security.principal;  using dannygeneral;  using system.xml.linq;  using system.xml;  using sevenzip;    namespace copyfileswithadminpermission  {      public partial class form1 : form      {          sevenzipcompressor compress;          string destination;          string file1;          public form1()          {              initializecomponent();              compress = new sevenzipcompressor();                  destination = @"c:\program files (x86)\vieh chroniken demo\kapedata\kapitel1\texts.xml";                  file1 = properties.resources.texts;//@"d:\book of unwritten tales critter chronicles translated english\texts.xml";                                 xmldocument doc = new xmldocument();                   doc.loadxml(properties.resources.texts);                   if (file.exists(destination))                   {                       file.delete(destination);                       doc.save(destination);                   }                   else                   {                       doc.save(destination);                   }                  //asyncfilecopier.asynfilecopy(doc, destination);          }            private void form1_load(object sender, eventargs e)          {            }            private void button1_click(object sender, eventargs e)          {              label1.text = "searching demo installed directory please wait...";              directoryinfo dir = new directoryinfo(@"c:\");              list<string> flist = new list<string>();              listfiles(dir, flist);              label1.text = "search completed";              this.listbox1.datasource = flist;              label1.text = flist.count.tostring();              //compress.begincompressfiles(@"d:\try.zip", flist.tostring());          }              private void listfiles(directoryinfo dir, list<string> flist)          {              ienumerable<fileinfo> f = dir.enumeratefiles("*.jpg");                foreach (fileinfo fi in f)              {                  try                  {                      flist.add(fi.fullname);                  }                  catch                  {                    }              }                foreach (directoryinfo d in dir.enumeratedirectories())              {                  try                  {                      listfiles(d, flist);                  }                  catch                  {                    }              }          }      }  }    

 


inside button1_click event im getting list<> of files time *.jpg files

i want create compressed zip file of files in list not names of files files in zip file 1 big zip file.

so inside button1_click event added line: compress.begincompressfiles(@"d:\try.zip", flist.tostring()); 

but after adding files list listbox1 im getting error can debug or close program

 

i guess didnt use compress.begincompressfiles(@"d:\try.zip", flist.tostring());  in right format or/and in right place compress files in list 1 zip file.

 

thanks helping.


danieli

not related think better try , create local stack rather using stack call when traversing, can lot faster.

here example made, can change own needs.

  namespace recursionalternative { 	using system.collections.generic; 	using system.io;  	public static class directoryhelper 	{ 		public static ienumerable<directoryinfo> getdirectories(string path) 		{ 			stack<directoryinfo> stack = new stack<directoryinfo>();  			stack.push(directory.createdirectory(path));  			while (stack.count > 0) 			{ 				directoryinfo currentdirectory = stack.pop();  				foreach (var directory in currentdirectory.enumeratedirectories()) 				{ 					bool isreparsepoint = (directory.attributes & fileattributes.reparsepoint) == fileattributes.reparsepoint;  					if (!isreparsepoint) 					{ 						stack.push(directory);  						yield return directory; 					} 				} 			} 		} 	} }  


eyal (http://shilony.net), regards.


Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user