日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
闡述VS2003壓縮代碼的有關(guān)常識(shí)

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

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


名稱欄目:闡述VS2003壓縮代碼的有關(guān)常識(shí)
標(biāo)題來源:http://www.5511xx.com/article/coespdi.html