zoukankan      html  css  js  c++  java
  • FileUpLoad

    单个文件的上传:
    保存到上传服务器指定目录: FileUpload1.Save(Server.MapPath("/upfiles/upload/") +FileUpload1.FileName);

    得到上传文件的文件名(含上传本地路径):FileUpload1.PostedFile.FileName;
    得到上传文件的大小:FileUpload1.PostedFile.ContentLength;
    得到上传文件上传类型:FileUpload1.PostedFile.ContentType;
    得到上传文件扩展名:System.IO.Path.GetExtension(FileUpload1.FileName);
    得到上传文件名:FileUpload1.FileName;

    同时多个文件的上传:
        方法是将 System.IO 类导入到 ASP.NET 页中,然后使用 HttpFileCollection 类捕获通过 Request 对象发送来的所有文件。该方法使您可以从一个页面上载所需数量的文件。

    使用 HttpFileCollection 类和 Request.Files 属性使您可以控制从该页上载的所有文件。
    (你可以在上传页面上放N个FileUpload控件)
    得到上传的文件名:System.IO.Path.GetFileName(FileUpload1.FileName);//Request.Files得到的多部分MIME格式的由客户端上载的文件的集合都是包含上传本地完整路径的。

    protected void Button1_Click(object sender, EventArgs e)
    {
       string filepath = Server.MapPath("/upfiles/upload/") ;

    }

    string vsfilename =fileupload1.FileName;//获取文件的名称 
    string vstype = vsfilename.Substring(vsfilename.LastIndexOf(".")).ToLower();//取文件的扩展名

    //判断文件类型
    string photoName1 = FileUploadText.PostedFile.FileName; //获取初始文件名 
    int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引 
    string newext = photoName1.Substring(i).ToLower(); //获取文件扩展名 
    if (newext != ".gif" && newext != ".jpg" && newext != ".jpeg" && newext != ".bmp" && newext != ".png")
    {
         Response.Write("<script language='javascript'>alert('格式不正确,请选择一张图片!');</script>");
    }
    else
    {    
         this.imgSend.Visible = true;
         this.Label3.Visible = true;
         this.Label4.Visible = false;
         FileUploadText.SaveAs(finalpath);
         this.imgSend.Visible = false;
         this.Label3.Visible = false;
         this.Label4.Visible = true;
    }

    使用FileUpload控件上传文件时对文件大小的限制可以在配置文件中配置。

    具体配置在System.Web配置节中中添加<httpRuntime maxRequestLength="10240"/>

    即可。具体对上传文件大小限制只要修改maxRequestLength的值就可以了。

  • 相关阅读:
    Android Studio 开发
    Jsp编写的页面如何适应手机浏览器页面
    电影
    Oracle 拆分列为多行 Splitting string into multiple rows in Oracle
    sql server 2008 自动备份
    WINGIDE 激活失败
    python安装 错误 “User installations are disabled via policy on the machine”
    ble编程-外设发送数据到中心
    iOS开发-NSString去掉所有换行及空格
    ios9 字符串与UTF-8 互相转换
  • 原文地址:https://www.cnblogs.com/lhqsw/p/2957462.html
Copyright © 2011-2022 走看看