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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Newface
    New Member
    • Feb 2012
    • 16

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

    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:

    Code:
    protected void cmdView_Click(object sender, EventArgs e)
        {    
    //ReadWriteData is a class   
            ReadWriteData rwd = new ReadWriteData();
            string sb = rwd.ReadFile(@"C:\Documents and Settings\pa_mukeshk\My Documents\Visual Studio 2008\Execute 1.0.docx");
            Session["FileData"] = sb;
            Response.Redirect("~/HomePages/ViewPage.aspx", true);
    //ReadWriteData class has below method
    public string ReadFile(string path)
        {
            FileStream fstream = new FileStream(path, FileMode.Open, FileAccess.Read);
            StreamReader sreader = new StreamReader(fstream, System.Text.Encoding.UTF8);
            string sr = sreader.ReadToEnd();
            return sr;
        }
    //on the load of ViewPage.aspx,i have
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string sb = (string)Session["FileData"];
                Label lt = new Label();
                lt.Text = sb.ToString();
                myPanel.Controls.Add(lt);
            }
        }
Working...