The code is very simple, do not be wordy.
C#:
<%@ Page language=" c#" autoeventwireup="true" %> <! DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Btnupload_click (object sender, EventArgs e) {if (FileUpload1.PostedFile.InputStream.Length < 1) { Msg.text = " Please select file. "; Return string FileName = Fileupload1.filename; if (Filename.tolower (). IndexOf (" txt" = = = 1) {msg.text = " Please select a text file. "; 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 = " you uploadThe file content is:<br/><br/>" + Sr. ReadToEnd (); Sr. Close (); Uploadstream.close (); Uploadstream = null; sr = null; } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title> directly read the contents of uploaded files without saving </title> </head> <body> <form id=" mengxianhui" Runat="server"> <asp:fileupload id=" fileupload1" runat="server" /> <asp:button id="btnupload" runat="server" text=" Upload " Onclick="btnupload_click"></asp:button> <p> <asp:label id=" msg" runat="server" forecolor=" Red"></asp:label></p> </form> </body&aMP;GT; </html>