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


--- 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   
+Priority: Wishlist
+Component: Sys.Web
+AssignedTo: gonzalo at ximian.com                            
+ReportedBy: vavra at software602.cz               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+Summary: HttpPostedFile.Filename encoding
+ 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 (==
+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,
+// Convert the new byte[] into a char[] and then into a string.
+char[] destChars = new char[Encoding.Unicode.GetCharCount(destBytes, 0,
+Encoding.Unicode.GetChars(destBytes, 0, destBytes.Length, destChars, 0);
+string destString = new string(destChars);
+return destString;

More information about the mono-bugs mailing list