[가져오기] 저장하지 않고 업로드된 파일의 내용을 직접 읽습니다.

2523 단어 파일 업로드

, 。

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 = " 。"; return; } string FileName = FileUpload1.FileName; if (FileName.ToLower().IndexOf(".txt") == -1) { Msg.Text = " 。"; 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 = " :<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> , </title> </head> <body> <form id="MengXianhui" runat="server"> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="btnUpload" runat="server" Text=" " OnClick="btnUpload_Click"></asp:Button> <p> <asp:Label ID="Msg" runat="server" ForeColor="Red"></asp:Label></p> </form> </body> </html>

기사 출처:
http://dotnet.aspx.cc/article/78280914-a75c-40dc-9dac-322b3d81be35/read.aspx

좋은 웹페이지 즐겨찾기