FineUI上传文件应用(三)

一、文件上传控件

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

二、文件上传的方法

 1  protected string ExcelUpload()
 2         {
 3             string path = "";
 4             if (Request.Files.Count > 0)
 5             {
 6                 HttpPostedFile file = Request.Files[0];
 7                 //判断是否上传文件
 8                 if (file.ContentLength > 0)
 9                 {
10                     //判断上传文件的类型
11                     if (file.ContentType == "" || file.ContentType == "")
12                     {
13                         //文件的名字
15                         string ext = System.IO.Path.GetExtension(file.FileName);
16                         Random r = new Random();
17                         //唯一的文件名
18                         string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + r.Next(1000, 10000) + ext;
19                         path = Request.MapPath("~/upload/" + filename);
20                         //保存上传的文件
21                         file.SaveAs(path);
22                         Response.Write("保存成功");
23                     }
24                     else
25                     {
26                         Response.Write("格式不正确");
27                     }
28                 }
29                 else
30                 {
31                     Response.Write("请上传文件失败");
32                 }
33             }
34             return path;
35         }

三、效果图

                                     

转载于:https://www.cnblogs.com/1312mn/p/3634349.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值