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

asp.net, c#

Solution

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...

Problem

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.

Original source