Directly read the contents of the uploaded file without saving

Source: Internet
Author: User

<%@ 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 voidBtnupload_click (Objectsender, EventArgs e) {    if(FileUpload1.PostedFile.InputStream.Length <1) {Msg.text="Please select a file. "; return; }    stringFileName =Fileupload1.filename; if(Filename.tolower (). IndexOf (". txt") == -1) {Msg.text="Please select a text file. "; return; }    intFileLen =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=NewSystem.IO.StreamReader (Uploadstream, System.Text.Encoding.Default); Msg.text="the content of the file you uploaded is:<br/><br/>"+Sr.    ReadToEnd (); Sr.    Close ();    Uploadstream.close (); Uploadstream=NULL; SR=NULL; }</script>"http://www.w3.org/1999/xhtml">"Server"> <title> Read the contents of the uploaded file directly without saving </title>"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>

Directly read the contents of the uploaded file without saving

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.