[Mono-bugs] [Bug 77714][Wis] New - HttpPostedFile.Filename encoding
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Mon Mar 6 04:26:03 EST 2006
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by vavra at software602.cz.
http://bugzilla.ximian.com/show_bug.cgi?id=77714
--- shadow/77714 2006-03-06 04:26:03.000000000 -0500
+++ shadow/77714.tmp.13627 2006-03-06 04:26:03.000000000 -0500
@@ -0,0 +1,51 @@
+Bug#: 77714
+Product: Mono: Class Libraries
+Version: 1.1
+OS: Red Hat 9.0
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: Sys.Web
+AssignedTo: gonzalo at ximian.com
+ReportedBy: vavra at software602.cz
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: HttpPostedFile.Filename encoding
+
+Hello,
+ for uploading file I use on client: <form><input type="file"></form>.
+
+In web.config I have
+<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
+This should say, what is source encoding for filename uploaded (==
+HttpPostedFile.Filename).
+
+The problem is, that HttpPostedFile.Filename stays UTF-8 encoded and it
+should be to UTF-16 conveted, because .NET type "string" is UTF-16.
+On MS.NET this is converted in UTF-16.
+
+Following method will fix this problem, but I suppose, it should be part of
+System.Web natively:
+
+public static string decodeHttpFileName(string Name) {
+ byte[] sourceBytes = new byte[Name.Length];
+ for (int i=0; i<Name.Length; i++) {
+ sourceBytes[i]= (byte)Name[i];
+ }
+
+// Convert utf8 -> unicode
+byte[] destBytes = Encoding.Convert(Encoding.UTF8, Encoding.Unicode,
+sourceBytes);
+
+// Convert the new byte[] into a char[] and then into a string.
+char[] destChars = new char[Encoding.Unicode.GetCharCount(destBytes, 0,
+destBytes.Length)];
+Encoding.Unicode.GetChars(destBytes, 0, destBytes.Length, destChars, 0);
+string destString = new string(destChars);
+
+return destString;
+}
More information about the mono-bugs
mailing list