364,088 Members | 5440 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

StreamReader to read word file-(output-Strange Characters)

Newface
P: 16
I am trying to read a word file and display it in a panel.
my idea is like below,which is not providing correct output:

Expand|Select|Wrap|Line Numbers
  1. protected void cmdView_Click(object sender, EventArgs e)
  2.     {    
  3. //ReadWriteData is a class   
  4.         ReadWriteData rwd = new ReadWriteData();
  5.         string sb = rwd.ReadFile(@"C:\Documents and Settings\pa_mukeshk\My Documents\Visual Studio 2008\Execute 1.0.docx");
  6.         Session["FileData"] = sb;
  7.         Response.Redirect("~/HomePages/ViewPage.aspx", true);
  8. //ReadWriteData class has below method
  9. public string ReadFile(string path)
  10.     {
  11.         FileStream fstream = new FileStream(path, FileMode.Open, FileAccess.Read);
  12.         StreamReader sreader = new StreamReader(fstream, System.Text.Encoding.UTF8);
  13.         string sr = sreader.ReadToEnd();
  14.         return sr;
  15.     }
  16. //on the load of ViewPage.aspx,i have
  17. protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.         if (!IsPostBack)
  20.         {
  21.             string sb = (string)Session["FileData"];
  22.             Label lt = new Label();
  23.             lt.Text = sb.ToString();
  24.             myPanel.Controls.Add(lt);
  25.         }
  26.     }
  27.  
Feb 9 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework