asp.net fileupload上传控件上传文件(专题教程:asp.net fileupload控件上传文件教程大全),代码:
后台.cs文件:
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
namespace linq_to_sql
{
public partial class testmemcache : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
}
protected void btnupload_click(object sender, eventargs e)
{
if (getuploadfilecontent.postedfile.inputstream.length < 1)
{
msg.text = "请选择文件";
return;
}
string filename = getuploadfilecontent.filename;//上传文件文件名
string filepath = getuploadfilecontent.postedfile.filename;//上传文件完整路径+文件名
if (filename.tolower().indexof(".htm") == -1)
{
msg.text = "请选择要求的类型的文件";
return;
}
int filelen = getuploadfilecontent.postedfile.contentlength;//获取上传文件的大小
byte[] input = new byte[filelen];
system.io.stream uploadstream = getuploadfilecontent.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;
}
}
}