C#SharpZipLib圧縮中国語ファイル名文字化けしの解決方法

1426 ワード

SharpZipLibを使用してマルチファイルのzip圧縮を生成する場合、中国語のファイル名に対して、圧縮パッケージに対応するファイル名は文字化けしています.
 
ネットユーザーたちの解決策はSharpZipLibソースコードの変更IsUnicodeText値の設定である.1つ目の方法は問題を解決できるはずだが、少し面倒だ.2つ目の方法は問題を解決できない.
 
ソースコードとヘルプを表示すると、SharpZipLibは、デフォルトの文字符号化方法を変更する静的方法DefaultCodePageを提供します.
 
以下に、DefaultCodePageのヘルプファイルの説明を示します.
 
Default encoding used for string conversion. 0 gives the default system OEM code page. Dont use unicode encodings if you want to be Zip compatible! Using the default code page isnt the full solution neccessarily there are many variable factors, codepage 850 is often a good choice for European users, however be careful about compatability.
 
では、ファイルの圧縮操作を行う前に、次の変更を行います.
 
//         CodePage  

Encoding gbk = Encoding.GetEncoding("gbk");

ICSharpCode.SharpZipLib.Zip.ZipConstants.DefaultCodePage = gbk.CodePage; 
 
中国語ファイル名のファイルが生成されたzipファイルを圧縮する場合は正常です.
 
使用されているSharpZipLibのバージョンは0.86版です.
 
参考記事:
 
Japanese Characters in Folder Names