• 批量上传文件


     

     上传多文件的页面设计

    绿茶配兔兔:
    protected void PLUpLoad_Click(object sender, EventArgs e)
    {

      //定义文件的保存路径
      string filepath = Server.MapPath("..\UploadFiles\RWGLAttachFile") + "\";
      HttpFileCollection uploadFiles = Request.Files;

      循环文件夹
      for (int i = 0; i < uploadFiles.Count; i++)
      {

        获取单个文件
        HttpPostedFile postedFile = uploadFiles[i];
        try
        {

          //如果文件是有内容的
          if (postedFile.ContentLength > 0)
         {
           Label1.Text += "已上传文件 #" + (i + 1) + ":" + System.IO.Path.GetFileName(postedFile.FileName) + "<br/>";

            postedFile.SaveAs(filepath + System.IO.Path.GetFileName(postedFile.FileName));//将文件保存到指定的路径中

            string fileType = "";

            fileType =System.IO.Path.GetExtension(postedFile.FileName)

            int slastDotIndex = postedFile.FileName.LastIndexOf(".");
            string sfileType = "";
            
    if (slastDotIndex >= 0)
            {
              sfileType = postedFile.FileName.Substring(slastDotIndex).ToLower();
            }
            string postedFileNofileType = postedFile.FileName.Remove(postedFile.FileName.Length - sfileType.Length);//不带文件后缀的文件名

            第二种方式

            string fileName2 = "";
            if (ContactTel.HasFile)
            {
              fileName2 = ContactTel.ShortFileName;

              fileName2 = fileName2.Replace(":", "_").Replace(" ", "_").Replace("\", "_").Replace("/", "_");
              int lastDotIndex = fileName2.LastIndexOf(".");
              string fileType = "";
              if (lastDotIndex >= 0)
                {
                fileType = fileName2.Substring(lastDotIndex).ToLower();
                }

                                       fileName2 = DateTime.Now.Ticks.ToString() + fileType;

                                       ContactTel.SaveAs(Server.MapPath("~/UploadFiles/RWGLAttachFile/" + fileName2));

                               }

               string FlowNode, SnID;
               int TXLCAID;

              bool retVal = Govaze.SQLServerDAL.Factory.getTXLCDAL().TXLC_new_Flow_ZLTX(1, //保存为草稿为0,提交为1"SPLC", //"质量体系的审批流程",postedFile.FileName,//fileName, //相关附件
              int.Parse(TreeID.Text), //所选择的设备所在的树节点InvolvedPerson.SelectedValue,InvolvedDept.Text, //故障发生地点fileName2, //相关附件的文件路径

      postedFileNofileType,//Text101.Text,//文件名称Remark101.Text, //故障描述Remark102.Text,//相关附件的文件名称Date101.Text == "" ? null : Date101.Text,null, //故障发生日期       Flow2Person.SelectedValue, //本流程不需要,赋值为空Flow3Person.SelectedValue, //本流程不需要,赋值为空Flow4Person.SelectedValue,getUserName(), out SnID, out FlowNode, out   TXLCAID);

             if (retVal){

              PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else{

              Alert.Show("失败,请重试!", MessageBoxIcon.Warning);
            }


             }
          }
        catch (Exception Ex)
        {
          Label1.Text += "发生错误: " + Ex.Message;
        }
        }

    }













     

     

     

  • 相关阅读:
    vue实战使用ajax请求后台数据(小白)
    jQuery实现tab栏切换效果
    jQuery下的ajax实例
    数据库之视图更新
    SQL Server 全文索引创建
    SQL Server 分区表
    数据快照 (Database Snapshot)
    FileStream
    ODBC,OLEDB,ADO,ADO.net,JDBC 理解
    拖延症?贪玩?来试试"百万金币时间管理法"
  • 原文地址:https://www.cnblogs.com/sanshengshitouhua/p/14366361.html
Copyright © 2020-2023  润新知