Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. reading special characters.

reading special characters.

Scheduled Pinned Locked Moved ASP.NET
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deepaks3
    wrote on last edited by
    #1

    Hi, I am reading the contents of a file and displaying it in a lable on a web page. There are also some special characters in the file such as : à é The problem is that these chars are converted to square blocks like this � in display. And this the the code i am using to read the file: FileStream file = new FileStream(FilePath, FileMode.Open, FileAccess.Read); // Create a new stream to read from a file StreamReader sr = new StreamReader(file); // Read contents of file into a string string s = sr.ReadToEnd(); // Close StreamReader sr.Close(); // Close file file.Close(); And this is the code whihc i am using to display the contents: lblStaticContent.Text = s.ToString(); Please help.

    Deepak Surana

    G 1 Reply Last reply
    0
    • D deepaks3

      Hi, I am reading the contents of a file and displaying it in a lable on a web page. There are also some special characters in the file such as : à é The problem is that these chars are converted to square blocks like this � in display. And this the the code i am using to read the file: FileStream file = new FileStream(FilePath, FileMode.Open, FileAccess.Read); // Create a new stream to read from a file StreamReader sr = new StreamReader(file); // Read contents of file into a string string s = sr.ReadToEnd(); // Close StreamReader sr.Close(); // Close file file.Close(); And this is the code whihc i am using to display the contents: lblStaticContent.Text = s.ToString(); Please help.

      Deepak Surana

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      A StreamReader by default uses the utf-8 encoding. If any other encoding was used when creating the file, you have to specify that encoding when you create the StreamReader.

      --- single minded; short sighted; long gone;

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups