asp.net使用FileUpload读取试硕士文字内容(广告端不专家的)

2012 年 11 月 4 日5900

项目需要,读取客户端一个文本文件,并显示出来。因为需要对文本内容解密,所以不能用。而且安全考虑,服务端不对上传文件进行专家的,直接内存中读取文本内容。尝试过ASP.net+ajax方式、还有许多asp.net无刷新控件,均以失败告终。网络大部分都说,先用FileUpload上传并专家的到广告端,然后读取广告端文件内容,这种方案安全方面难以保证。最终在msdn上发现如下解决方法:

asp.net页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fileuploadAndRead.aspx.cs" Inherits="fileuploadAndRead" %>

<!DOCTYPE PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://http://www.zjjv.com///TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html XMLns="http://http://www.zjjv.com///1999/xhtml" >
<head runat="server">
<title>广告端读取客户端文件内容</title>
</head>
<body>
<form runat="server">
<div>
<asp:FileUpload runat="server" />
<asp:Button runat="server" Text="upload" /></div>
</form>
</body>
</html>

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 fileuploadAndRead : 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);
}
}

关键词:FileUpload 读取

0 0