zoukankan      html  css  js  c++  java
  • 批量上传文件

     

     上传多文件的页面设计

    绿茶配兔兔:
    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;
        }
        }

    }













     

     

     

  • 相关阅读:
    【剑指offer】面试题16、反转链表
    【剑指offer】面试题15、链表中倒数第 K 个结点
    【剑指offer】面试题14、调整数组顺序使奇数位于偶数前面
    oracle sql与调优
    linux 常用命令记录 持续更新
    函数重载中形参的const
    mem_fun_ref和mem_fun的用法
    c++风格的格式化输出
    count_if函数里面的第三个参数的书写方式<<0926
    操作符重载(++,+,输入输出,强制类型转换)
  • 原文地址:https://www.cnblogs.com/sanshengshitouhua/p/14366361.html
Copyright © 2011-2022 走看看