最近有人問到這個問題...小弟就寫個範例分享給大家呀..
這個功能主要是不用先上傳檔案到Server端..直接用StreamReader將文字檔讀取出來...
asp.net(c#)
fileuploadTest.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fileuploadTest.aspx.cs" Inherits="fileuploadTest" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>fileuploadTest</title> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="upload" /></div> </form> </body> </html>
fileuploadTest.aspx.cs
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class fileuploadTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { System.IO.StreamReader red = new System.IO.StreamReader(this.FileUpload1.PostedFile.InputStream, System.Text.Encoding.Default); string strContent = red.ReadToEnd(); Response.Write(strContent); } }
執行結果:
參考網址:
http://www.blueshop.com.tw/board/show.asp?subcde=BRD200806041144324QA&fumcde=FUM20041006161839LRJhttp://topic.csdn.net/t/20060926/18/5049873.html