The code is very simple.
C #:
& Lt; % @ Page Language = & quot; C # & quot; AutoEventWireup = & quot; true & quot; % & gt; & lt ;! DOCTYPE html PUBLIC & quot;-// W3C // dtd xhtml 1.0 Transitional // EN & quot; http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script Runat = & quot; server & quot; & gt; protected void btnUpload_Click (object sender, EventArgs e) {if (FileUpload1.PostedFile. inputStream. length & lt; 1) {Msg. text = & quot; select a file. & Quot; return;} string FileName = FileUpload1.FileName; if (FileName.ToLower().IndexOf(&quot;.txt & quot;) =-1) {Msg. Text = & quot; select a Text file. & Quot; return;} int FileLen = FileUpload1.PostedFile. contentLength; byte [] input = new byte [FileLen]; System. IO. stream UpLoadStream = FileUpload1.PostedFile. inputStream; UpLoadStream. read (input, 0, FileLen); UpLoadStream. position = 0; System. IO. streamReader sr = new System. IO. streamReader (UpLoadStream, System. text. encoding. default); Msg. text = & quot; the content of the file you uploaded is: & lt; br/& gt; & quot; + sr. readToEnd (); sr. close (); UpLoadStream. close (); UpLoadStream = null; sr = null ;}& lt;/script & gt; & lt; html xmlns = & quot; http://www.w3.org/1999/xhtml"><pead Runat = & quot; server & quot; & gt; & lt; title & gt; read the content of the uploaded file without saving & lt;/title & gt; & lt; /head & gt; & lt; body & gt; & lt; form id = & quot; MengXianhui & quot; runat = & quot; server & quot; & gt; & lt; asp: FileUpload ID = & quot; FileUpload1 & quot; runat = & quot; server & quot;/& gt; & lt; asp: Button ID = & quot; btnUpload & quot; runat = & quot; server & quot; Text = & quot; upload & quot; OnClick = & quot; btnUpload_Click & quot; & gt; & lt;/asp: Button & gt; & lt; p & gt; & lt; asp: Label ID = & quot; Msg & quot; runat = & quot; server & quot; ForeColor = & quot; Red & quot; & gt; & lt;/asp: Label & gt; & lt;/p & gt; & lt;/form & gt; & lt;/body & gt; & lt; /html & gt;