Writing a string in utf8 format to a zip file (Ionic.Zip)

I have a problem with the output line being formatted in utf8 format. I am currently writing the ansi line for a zip file without problems, for example:

StreamReader tr = new StreamReader( "myutf8-file.xml");
String myfilecontent = tr.ReadToEnd();
ZipFile zip = new ZipFile());
zip.AddFileFromString("my.xml", "", myfilecontent  );

How to force a string (contents of my.xml file) to be UTF8.

+3
source share
1 answer

Do not use the obsolete method AddFileFromString. Use instead AddEntry(string, string, string, Encoding):

zip.AddEntry("my.xml", "", myfilecontent, Encoding.UTF8);

If you are actually reading a UTF-8 text file to start with it, why not just open the stream and pass it to AddEntry? No need to decode from UTF-8 and then re-encode ...

+9
source

Source: https://habr.com/ru/post/1717226/


All Articles