自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

闡述VS2003壓縮代碼的有關(guān)常識

開發(fā) 后端
我們經(jīng)常會遇到編制VS2003壓縮代碼的問題,也會遇到將VS2003壓縮代碼修改的的問題。那么,如何解決此類問題呢?下文就給大家進(jìn)行全面的講解。

昨天到今天搞了一整天的VS2003壓縮代碼,我都快崩潰了! 一看到那些代碼,腦袋頓時(shí)就像爆炸一樣,所以有了許多的問題出現(xiàn),還好,我一個(gè)個(gè)把他記錄下來了,同時(shí),在相關(guān)論壇上找了一些相關(guān)的解決辦法,分享一下,供大家相互學(xué)習(xí)交流

1、首先從這里下載0.84版本的VS2003壓縮代碼及示例碼。

2、下載下來之后你發(fā)現(xiàn)它沒有VS2003的解決方案文件,沒有關(guān)系。你可以自己建立,首先新建一個(gè)ZipUnzip的解決方案,然后,將上面經(jīng)過解壓縮之后的所有文件及目錄COPY到你的解決方案所在的目錄下。 #t#

3、在VS2003解決方案資源管理器(一般是在右上方中部點(diǎn)的位置)中點(diǎn)擊顯示所有文件按鈕,然后可以見到很多“虛”的圖標(biāo)、文件及文件夾等,可以一次選擇它們,然后包含進(jìn)項(xiàng)目中。

4、編譯,***使用Release選項(xiàng),編譯完成之后你可以在\bin\Release\看到ZipUnzip.dll的類了。如果你編譯時(shí)報(bào)錯(cuò),說什么AssemblyKeyFile之類的,你可以使用強(qiáng)命名工具新建一個(gè),也可以將AssemblyInfo.cs中[assembly: AssemblyKeyFile("。。。。。")]改成:[assembly: AssemblyKeyFile("")] (不推薦這樣做)。

5、新建一個(gè)WEBFORM項(xiàng)目,添加ZipUnzip.dll類的引用,然后添加如下文件及內(nèi)容:

  1. using System;  
  2. using System.IO;  
  3. using ICSharpCode.SharpZipLib.Zip;  
  4. using ICSharpCode.SharpZipLib.GZip;  
  5. using ICSharpCode.SharpZipLib.BZip2;  
  6. using ICSharpCode.SharpZipLib.Checksums;  
  7. using ICSharpCode.SharpZipLib.Zip.Compression;  
  8. using ICSharpCode.SharpZipLib.Zip.Compression.Streams;  
  9.  
  10. namespace WebZipUnzip  
  11. {  
  12.  public class AttachmentUnZip  
  13.  {  
  14. public AttachmentUnZip()  
  15. {}  
  16. public static void UpZip(string zipFile)  
  17. {  
  18. string []FileProperties=new string[2];  
  19. FileProperties[0]=zipFile;//待解壓的文件  
  20. FileProperties[1]=zipFile.Substring(0,zipFile.LastIndexOf("\\")+1);//解壓后放置的目標(biāo)目錄  
  21. UnZipClass UnZc=new UnZipClass();  
  22. UnZc.UnZip(FileProperties);  
  23. }  
  24.  }  
  25. }  
  26.  
  27. // ---------------------------------------------  
  28. // 2. UnZipClass.cs  
  29. // ---------------------------------------------  
  30.  
  31. using System;  
  32. using System.IO;  
  33. using ICSharpCode.SharpZipLib.Zip;  
  34. using ICSharpCode.SharpZipLib.GZip;  
  35. using ICSharpCode.SharpZipLib.BZip2;  
  36. using ICSharpCode.SharpZipLib.Checksums;  
  37. using ICSharpCode.SharpZipLib.Zip.Compression;  
  38. using ICSharpCode.SharpZipLib.Zip.Compression.Streams;  
  39.  
  40. namespace WebZipUnzip  
  41. {  
  42.  public class UnZipClass  
  43.  {   
  44. ///   
  45. /// 解壓文件  
  46. ///   
  47. /// 包含要解壓的文件名和要解壓到的目錄名數(shù)組  
  48. public void UnZip(string[] args)  
  49. {  
  50. ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));  
  51. try  
  52. {   
  53.  ZipEntry theEntry;  
  54.  while ((theEntry = s.GetNextEntry()) != null)   
  55.  {   
  56. string directoryName = Path.GetDirectoryName(args[1]);  
  57. string fileName = Path.GetFileName(theEntry.Name);  
  58.  
  59. //生成解壓目錄  
  60. Directory.CreateDirectory(directoryName);  
  61.  
  62. if (fileName != String.Empty)   
  63. {   
  64. //解壓文件到指定的目錄  
  65. FileStream streamWriter = File.Create(args[1]+fileName);  
  66. int size = 2048;  
  67. byte[] data = new byte[2048];  
  68. while (true)   
  69. {  
  70.  ssize = s.Read(data, 0, data.Length);  
  71.  if (size > 0)   
  72.  {  
  73. streamWriter.Write(data, 0, size);  
  74.  }   
  75.  else   
  76.  {  
  77. break;  
  78.  }  
  79. }  
  80. streamWriter.Close();  
  81. }  
  82.  }  
  83.  s.Close();  
  84. }  
  85. catch(Exception eu)  
  86. {  
  87.  throw eu;  
  88. }  
  89. finally  
  90. {  
  91.  s.Close();  
  92. }  
  93. }//end UnZip  
  94.  
  95. public static bool UnZipFile(string file, string dir)  
  96. {  
  97. try  
  98. {  
  99.  if (!Directory.Exists(dir))  
  100. Directory.CreateDirectory(dir);  
  101. string fileFullName = Path.Combine(dir,file);  
  102. ZipInputStream s = new ZipInputStream(File.OpenRead( fileFullName ));  
  103.    
  104. ZipEntry theEntry;  
  105. while ((theEntry = s.GetNextEntry()) != null)  
  106. {  
  107. string directoryName = Path.GetDirectoryName(theEntry.Name);  
  108. string fileName = Path.GetFileName(theEntry.Name);  
  109.    
  110. if (directoryName != String.Empty)  
  111.  Directory.CreateDirectory( Path.Combine(dir, directoryName));  
  112.  if (fileName != String.Empty)  
  113.  {  
  114. FileStream streamWriter = File.Create( Path.Combine(dir,theEntry.Name) );  
  115. int size = 2048;  
  116. byte[] data = new byte[2048];  
  117. while (true)  
  118. {  
  119. ssize = s.Read(data, 0, data.Length);  
  120. if (size > 0)  
  121. {  
  122.  streamWriter.Write(data, 0, size);  
  123. }  
  124. else  
  125. {  
  126.  break;  
  127. }  
  128. }  
  129. streamWriter.Close();  
  130.  }  
  131. }  
  132. s.Close();  
  133. return true;  
  134. }  
  135. catch (Exception)  
  136. {  
  137. throw;  
  138. }  
  139.  }  
  140. }//end UnZipClass  

此方案解決了文件名中文字的問題,目錄VS2003壓縮代碼問題,至于整個(gè)文件夾批量上傳并壓縮成一個(gè)WINZIP壓縮包的問題,沒有時(shí)間解決了,各位如有解決方案,不妨共享一下。

責(zé)任編輯:chenqingxiang 來源: 計(jì)世網(wǎng)
相關(guān)推薦

2009-11-26 17:02:29

VS2003配置

2009-12-01 14:30:08

VS2003使用

2009-11-30 09:27:38

VS2003源代碼

2009-11-25 10:14:43

2009-12-15 13:39:43

2009-11-30 09:16:44

VS2003源代碼

2009-11-27 08:59:29

VS2003配置文件

2009-12-18 10:10:49

VS 2003程序

2009-12-09 13:41:04

VS 2003 報(bào)錯(cuò)

2009-11-30 13:51:28

2009-11-26 13:55:35

VS2003源代碼

2009-12-09 16:52:51

VS 2003插件

2009-11-30 15:57:18

VS2003 MFC

2009-11-30 11:05:19

VS2003 WebS

2009-12-01 10:54:48

VS2003 英文版

2009-11-30 17:28:39

VS2003 ASP

2009-11-30 16:50:26

VS2003調(diào)試

2009-12-01 15:32:48

VS2003配置

2009-11-25 13:57:25

VS2003發(fā)布

2009-12-01 17:55:11

VS2003配置
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號