I have a problem that output string must be utf8-formatted, I am writing currently ansi string to zip file without problems like this:
StreamReader tr = new StreamReader( "myutf8-file.xml");
String myfilecontent = tr.ReadToEnd();
ZipFile zip = new ZipFile());
zip.AddFileFromString("my.xml", "", myfilecontent );
How to force string (my.xml file content) to be UTF8.
Don't use the deprecated AddFileFromString
method. Use AddEntry(string, string, string, Encoding)
instead:
zip.AddEntry("my.xml", "", myfilecontent, Encoding.UTF8);
If you're actually reading a UTF-8 text file to start with though, why not just open the stream and pass that into AddEntry
? There's no need to decode from UTF-8 and then re-encode...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With