Monotouch – ICSharpCode.SharpZipLib给出错误

前端之家收集整理的这篇文章主要介绍了Monotouch – ICSharpCode.SharpZipLib给出错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Hy家伙,

我正在尝试使用ICSharpCode.SharpZipLib库生成一个Zip文件,但它会引起一个非常奇怪的错误.

码:

  1. public static void ZipFiles(string inputFolderPath,string outputPathAndFile,string password)
  2. {
  3. ArrayList ar = GenerateFileList(inputFolderPath); // generate file list
  4. int TrimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;
  5.  
  6. TrimLength += 1; //remove '\'
  7. FileStream ostream;
  8. byte[] obuffer;
  9.  
  10. ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outputPathAndFile)); // create zip stream
  11. if (password != null && password != String.Empty)
  12. oZipStream.Password = password;
  13. oZipStream.SetLevel(9); // maximum compression
  14. ZipEntry oZipEntry;
  15. foreach (string Fil in ar) // for each file,generate a zipentry
  16. {
  17. oZipEntry = new ZipEntry(Fil.Remove(0,TrimLength));
  18. oZipStream.PutNextEntry(oZipEntry);
  19.  
  20. if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
  21. {
  22. ostream = File.OpenRead(Fil);
  23. obuffer = new byte[ostream.Length];
  24. ostream.Read(obuffer,obuffer.Length);
  25. oZipStream.Write(obuffer,obuffer.Length);
  26. }
  27. }
  28. oZipStream.Finish();
  29. oZipStream.Close();
  30. }
  31.  
  32.  
  33. private static ArrayList GenerateFileList(string Dir)
  34. {
  35. ArrayList fils = new ArrayList();
  36. bool Empty = true;
  37. foreach (string file in Directory.GetFiles(Dir,"*.xml")) // add each file in directory
  38. {
  39. fils.Add(file);
  40. Empty = false;
  41. }
  42.  
  43. if (Empty)
  44. {
  45. if (Directory.GetDirectories(Dir).Length == 0)
  46. // if directory is completely empty,add it
  47. {
  48. fils.Add(Dir + @"/");
  49. }
  50. }
  51.  
  52. foreach (string dirs in Directory.GetDirectories(Dir)) // recursive
  53. {
  54. foreach (object obj in GenerateFileList(dirs))
  55. {
  56. fils.Add(obj);
  57. }
  58. }
  59. return fils; // return file list
  60. }

错误

  1. Unhandled Exception: System.NotSupportedException: CodePage 437 not supported
  2. at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0
  3. at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToArray (System.String str) [0x00000] in <filename unknown>:0
  4. at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToArray (Int32 flags,System.String str) [0x00000] in <filename unknown>:0
  5. at ICSharpCode.SharpZipLib.Zip.ZipOutputStream.PutNextEntry (ICSharpCode.SharpZipLib.Zip.ZipEntry entry) [0x00000] in <filename unknown>:0
  6. at WpfPrototype1.MainInvoicesView.ZipFiles (System.String inputFolderPath,System.String outputPathAndFile,System.String password) [0x00000] in <filename unknown>:0
  7. at WpfPrototype1.MainInvoicesView.<ViewDidLoad>m__6 (System.Object,System.EventArgs ) [0x00000] in <filename unknown>:0
  8. at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in <filename unknown>:0
  9. at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  10. at MonoTouch.UIKit.UIApplication.Main (System.String[] args,System.String principalClassName,System.String delegateClassName) [0x00000] in <filename unknown>:0
  11. at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in <filename unknown>:0
  12. at WpfPrototype1.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0

如何使代码支持CodePage 437?

问候,
克劳迪奥

解决方法

MonoTouch删除了I18N代码页,它不能静态地确定您需要的.在这种情况下,您可以强制使用monotouch来保存所需的代码页集合(West):两种方式之一:

>单击Project-> [ProjectName]选项
>选择iPhone Build
>你现在有两个选择
一个.从I18n装配体列表中选择“西”
湾将“-i18n =西”添加到“额外参数”

注意:对于配置和平台的每个组合,您都需要执行步骤3.

猜你在找的iOS相关文章