您的位置:首页 > 产品设计 > UI/UE

FineUI上传文件应用(三)

2014-03-30 17:46 162 查看
一、文件上传控件

<x:FileUpload runat="server" ID="file" EmptyText="请选择文件" Label="选择文件" AutoPostBack="true">
</x:FileUpload>


二、文件上传的方法

protected string ExcelUpload()
{
string path = "";
if (Request.Files.Count > 0)
{
HttpPostedFile file = Request.Files[0];
//判断是否上传文件
if (file.ContentLength > 0)
{
//判断上传文件的类型
if (file.ContentType == "" || file.ContentType == "")
{
//文件的名字
string ext = System.IO.Path.GetExtension(file.FileName);
Random r = new Random();
//唯一的文件名
string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + r.Next(1000, 10000) + ext;
path = Request.MapPath("~/upload/" + filename);
//保存上传的文件
file.SaveAs(path);
Response.Write("保存成功");
}
else
{
Response.Write("格式不正确");
}
}
else
{
Response.Write("请上传文件失败");
}
}
return path;
}


三、效果图

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: