On my website, I have the opportunity to upload all the images uploaded by users. The problem is the images with Hebrew names (I need the original file name). I tried to decode the file names, but this does not help. Here is the code:
using ICSharpCode.SharpZipLib.Zip; Encoding iso = Encoding.GetEncoding("ISO-8859-1"); Encoding utf8 = Encoding.UTF8; byte[] utfBytes = utf8.GetBytes(file.Name); byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes); string name = iso.GetString(isoBytes); var entry = new ZipEntry(name + ".jpg"); zipStream.PutNextEntry(entry); using (var reader = new System.IO.FileStream(file.Name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { byte[] buffer = new byte[ChunkSize]; int bytesRead; while ((bytesRead = reader.Read(buffer, 0, buffer.Length)) > 0) { byte[] actual = new byte[bytesRead]; Buffer.BlockCopy(buffer, 0, actual, 0, bytesRead); zipStream.Write(actual, 0, actual.Length); } }
After utf-8 encoding, I get the names of the hieroglyphs, for example: ??????. jpg Where is my mistake?
source share