Read and display contents of HTML file on ASP.Net page

Last Reply on Dec 05, 2014 03:02 AM By Azim

Posted on Dec 05, 2014 02:58 AM

In D Folder files are stored with the name of course name. In D folder list of files as follows RM.html     (file) I have one design page as follows Course name       Dropdownlist (In dropdownlist all course will be displayed)RM(Course) Then i have one Button Show Button. When i select the Course (RM). i want to display the RM file content details. For that how can i do using c#. Display files from folder using c#.

Posted on Dec 05, 2014 03:02 AM Modified on on Dec 05, 2014 04:20 AM


  1. Read HTML file and display it on ASP.Net Web Page

For selecting the files from the folder you need to make use of FileUpload control.

Please refer this code


<form id="form1" runat="server">
    <asp:FileUpload ID="fuFileUpload" runat="server" />
    <asp:Button Text="Upload and Display html File" OnClick="UploadDisplay" runat="server" />
    <br />
    <div id="dvHtml" runat="server">


using System.IO;


protected void UploadDisplay(object sender, EventArgs e)
    if (this.fuFileUpload.HasFile)
        this.fuFileUpload.PostedFile.SaveAs(Server.MapPath("~/HTMLFiles/" + Path.GetFileName(this.fuFileUpload.FileName)));
    string body = string.Empty;
    using (System.IO.StreamReader reader = new System.IO.StreamReader(Server.MapPath("~/HTMLFiles/" + Path.GetFileName(this.fuFileUpload.FileName))))
        dvHtml.InnerHtml = reader.ReadToEnd();