Hy家伙,
我正在尝试使用ICSharpCode.SharpZipLib库生成一个Zip文件,但它会引起一个非常奇怪的错误.
码:
public static void ZipFiles(string inputFolderPath,string outputPathAndFile,string password) { ArrayList ar = GenerateFileList(inputFolderPath); // generate file list int TrimLength = (Directory.GetParent(inputFolderPath)).ToString().Length; TrimLength += 1; //remove '\' FileStream ostream; byte[] obuffer; ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outputPathAndFile)); // create zip stream if (password != null && password != String.Empty) oZipStream.Password = password; oZipStream.SetLevel(9); // maximum compression ZipEntry oZipEntry; foreach (string Fil in ar) // for each file,generate a zipentry { oZipEntry = new ZipEntry(Fil.Remove(0,TrimLength)); oZipStream.PutNextEntry(oZipEntry); if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory { ostream = File.OpenRead(Fil); obuffer = new byte[ostream.Length]; ostream.Read(obuffer,obuffer.Length); oZipStream.Write(obuffer,obuffer.Length); } } oZipStream.Finish(); oZipStream.Close(); } private static ArrayList GenerateFileList(string Dir) { ArrayList fils = new ArrayList(); bool Empty = true; foreach (string file in Directory.GetFiles(Dir,"*.xml")) // add each file in directory { fils.Add(file); Empty = false; } if (Empty) { if (Directory.GetDirectories(Dir).Length == 0) // if directory is completely empty,add it { fils.Add(Dir + @"/"); } } foreach (string dirs in Directory.GetDirectories(Dir)) // recursive { foreach (object obj in GenerateFileList(dirs)) { fils.Add(obj); } } return fils; // return file list }
错误:
Unhandled Exception: System.NotSupportedException: CodePage 437 not supported at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unkNown>:0 at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToArray (System.String str) [0x00000] in <filename unkNown>:0 at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToArray (Int32 flags,System.String str) [0x00000] in <filename unkNown>:0 at ICSharpCode.SharpZipLib.Zip.ZipOutputStream.PutNextEntry (ICSharpCode.SharpZipLib.Zip.ZipEntry entry) [0x00000] in <filename unkNown>:0 at WpfPrototype1.MainInvoicesView.ZipFiles (System.String inputFolderPath,System.String outputPathAndFile,System.String password) [0x00000] in <filename unkNown>:0 at WpfPrototype1.MainInvoicesView.<ViewDidLoad>m__6 (System.Object,System.EventArgs ) [0x00000] in <filename unkNown>:0 at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in <filename unkNown>:0 at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at MonoTouch.UIKit.UIApplication.Main (System.String[] args,System.String principalClassName,System.String delegateClassName) [0x00000] in <filename unkNown>:0 at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in <filename unkNown>:0 at WpfPrototype1.Application.Main (System.String[] args) [0x00000] in <filename unkNown>:0
问候,
克劳迪奥
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。