开发者

Encoding Issue ASP.net

i upload a file with ASP.net which Contains an "ä" or "ü", when uploaded, on the server the "ä" or "ü" is replaced with another special character. How can i solve this issue. Same Problem is with normal textboxes, so i guess it has to do so开发者_StackOverflow中文版mething with Encoding.

Maybe u have got a solution or an idea, would be quite nice...:-)


Most likely an encoding issue.

You could check:

  • Whether the encoding meta tag on the HTML page is correct.
  • Whether the pages are sending the correct encoding to the client (in the HTTP header)
  • Whether the pages are actually encoded in the correct encoding (via VS.NET "File" menu, menu item "Advanced Save Options").

To see the HTTP headers, use e.g. ieHttpHeaders extension for Internet Explorer.

To change the sent encoding, use either the <globalization> tag in WEB.CONFIG to change for all pages or use the @Page directive to define the response encoding on a per-page-basis.


put following code in web.config

<configuration>
  <system.web>
    <globalization
      fileEncoding="utf-8"
      requestEncoding="utf-8"
      responseEncoding="utf-8"
      />
  </system.web>
</configuration>


if(File.Exists(Server.MapPath("../App_Data/Karten/") + FileUpload1.PostedFile.FileName.Replace("ö","oe").Replace("Ö","Oe").Replace("Ö","ae").Replace("ä","Ae").Replace("ü","ue").Replace("Ü","Ue"))){ Label1.Text = "Datei existiert bereits"; }else{ string filepath = FileUpload1.PostedFile.FileName; System.Diagnostics.Debug.WriteLine("Filename" + filepath);

        System.Diagnostics.Debug.WriteLine("Filename" + filepath.Replace("ö","oe").Replace("Ö","Oe").Replace("Ö","ae").Replace("ä","Ae").Replace("ü","ue").Replace("Ü","Ue"));
        if (FileUpload1.PostedFile.FileName.ToLower().EndsWith("jpeg") || FileUpload1.PostedFile.FileName.ToLower().EndsWith("jpg"))
        {

        System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);


            if (UploadedImage == null)
              {
                Label1.Text = "Kein Bild";
                System.IO.File.Delete(Server.MapPath("../App_Data/Karten/") + filepath);
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜