FileUpdate--上传控件

protected   void  Button1_Click( object  sender, EventArgs e)
    
{
        
string name = FileUpload1.FileName;   //上传文件名
        string size = FileUpload1.PostedFile.ContentLength.ToString();   //文件大小(字节)
        string type = FileUpload1.PostedFile.ContentType;   //获取上传文件的MIME内容类型
        string type1 = name.Substring(name.LastIndexOf("."+ 1);  //name.LastIndexOf(".")索引name中"."的位置+1,就是后缀名的index
        string ipath = Server.MapPath("upimg"+ "\\" + name;
        
string fpath = Server.MapPath("upfile"+ "\\" + name;
        
string wpath = "upimg" + "\\" + name;
        
if (type1 == "jpg" || type1 == "gif" || type1 == "bmp" || type1 == "png")
        
{
            FileUpload1.SaveAs(ipath);
            Image1.ImageUrl 
= wpath;
            Label1.Text 
= "文件名" + name + "<br>" + "文件大小为" + size + "<br>文件类型是" + type + "<br>后缀名" + type1 + "<br>实际路径" + ipath + "<br>虚拟路径" + wpath;
        }

        
else
        
{
            FileUpload1.SaveAs(fpath);
            Image1.ImageUrl 
= wpath;
            Label1.Text 
= "文件名" + name + "<br>" + "文件大小为" + size + "<br>文件类型是" + type + "<br>后缀名" + type1 + "<br>实际路径" + ipath + "<br>虚拟路径" + wpath;
        }

    }
运行结果:

转载于:https://www.cnblogs.com/net123/archive/2007/12/25/1014803.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值