首页 > 代码库 > 不经保存,直接读取上传文件的内容
不经保存,直接读取上传文件的内容
<%@ 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>
不经保存,直接读取上传文件的内容
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。