不上传多个文件只拍摄第一个文件 [英] Not uploading multiple files only first file taken

查看:83
本文介绍了不上传多个文件只拍摄第一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一个文件仅被选中。但在

My first file is getting selected only. but in

HttpPostedFile 

显示第二个文件名。



我尝试了什么:



second file name is showing.

What I have tried:

protected void btnUploadImage_Click(object sender, EventArgs e)
       {


           string birthDate = Date.Text;
           var split = birthDate.Split('/');
           var yearSplit = split[2];
           string VenName = VendorName.Text;
           //string directoryPath = Server.MapPath(string.Format("~/{0}/", txtFolderName.Text.Trim()));
           // string folderPath =Server.MapPath( @yearSplit + "\\");
           string folderPath = @"E:\\" + yearSplit + "\\";
           string folderPath1 = folderPath + VenName + "\\";
           string folderPath2 = folderPath1 + ddlVoucherType.Text + "\\";
           string file_name = SelectFile.FileName.ToString();
           string folderPathFinal = folderPath2 + file_name;

           //DateTime birthDate1 = DateTime.Now.Date;
           //var year = birthDate1.Year;
           //var month = birthDate1.Month;
           //var day = birthDate1.Day;

           if (SelectFile.HasFiles)
           {
               int filecount = 0;
               int fileuploadcount = 0;
               //check No of Files Selected
               filecount = SelectFile.PostedFiles.Count();
               if (filecount <= 10)
               {

                   foreach (HttpPostedFile postfiles in SelectFile.PostedFiles)
                   {
                       fileuploadcount++;
                       if (ddlVoucherType.Text.ToString() == "Sale")
                       {

                           //Check whether Directory (Folder) exists.

                           if (!Directory.Exists(folderPath) || !Directory.Exists(folderPath1) || !Directory.Exists(folderPath2))
                           {
                               //If Directory (Folder) does not exists. Create it.
                               Directory.CreateDirectory(folderPath2);
                               SelectFile.SaveAs(folderPath2 + Path.GetFileName(SelectFile.FileName));
                               MessageBox.Show(Path.GetFileName(SelectFile.FileName) + " has been uploaded.");

                           }

                           else if (!Directory.Exists(folderPath) || !Directory.Exists(folderPath1))
                           {
                               //If Directory (Folder) does not exists. Create it.
                               Directory.CreateDirectory(folderPath1);
                               SelectFile.SaveAs(folderPath1 + Path.GetFileName(SelectFile.FileName));
                               MessageBox.Show(Path.GetFileName(SelectFile.FileName) + " has been uploaded.");

                           }
                           else if (!Directory.Exists(folderPath))
                           {

                               Directory.CreateDirectory(folderPath);
                               SelectFile.SaveAs(folderPath + Path.GetFileName(SelectFile.FileName));
                               MessageBox.Show(Path.GetFileName(SelectFile.FileName) + " has been uploaded.");

                           }
                           else
                           {
                               SelectFile.SaveAs(folderPath2 + Path.GetFileName(SelectFile.FileName));
                               MessageBox.Show(Path.GetFileName(SelectFile.FileName) + " has been uploaded.");

                           }
                       }
                       else
                       {

                           //string folderPath = @"E:\\2016-17\\";
                           //string folderPath1 = @"E:\\2016-17\\" + " Vendor\\";
                           //string folderPath2 = @"E:\\2016-17\\" + " Vendor\\" + "Purchase\\";
                           //Check whether Directory (Folder) exists.

                           if (!Directory.Exists(folderPath) || !Directory.Exists(folderPath1) || !Directory.Exists(folderPath2))
                           {
                               //If Directory (Folder) does not exists. Create it.
                               Directory.CreateDirectory(folderPath2);
                               SelectFile.SaveAs(folderPath2 + Path.GetFileName(SelectFile.FileName));
                               MessageBox.Show(Path.GetFileName(SelectFile.FileName) + " has been uploaded.");


                           }

                           else if (!Directory.Exists(folderPath) || !Directory.Exists(folderPath1))
                           {
                               //If Directory (Folder) does not exists. Create it.
                               Directory.CreateDirectory(folderPath1);
                               SelectFile.SaveAs(folderPath1 + Path.GetFileName(SelectFile.FileName));
                               MessageBox.Show(Path.GetFileName(SelectFile.FileName) + " has been uploaded.");


                           }
                           else if (!Directory.Exists(folderPath))
                           {

                               Directory.CreateDirectory(folderPath);
                               SelectFile.SaveAs(folderPath + Path.GetFileName(SelectFile.FileName));
                               MessageBox.Show(Path.GetFileName(SelectFile.FileName) + " has been uploaded.");

                           }
                           else
                           {
                               SelectFile.SaveAs(folderPath2 + Path.GetFileName(SelectFile.FileName));
                               MessageBox.Show(Path.GetFileName(SelectFile.FileName) + " has been uploaded.");

                           }

                       }
                     //  fileuploadcount++;
                   }
               }

               Stream fs = SelectFile.PostedFile.InputStream;
               BinaryReader br = new BinaryReader(fs);
               Byte[] bytes = br.ReadBytes((Int32)fs.Length);




               //save data
               SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

               SqlCommand cmd = new SqlCommand("SaveUploadFiles", con);
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("ImageName", file_name);
               cmd.Parameters.AddWithValue("ImagePath", folderPathFinal);
               cmd.Parameters.AddWithValue("Image", fs);
               cmd.Parameters.AddWithValue("VoucherType", ddlVoucherType.Text);
               cmd.Parameters.AddWithValue("VendorId", VenName);
               cmd.Parameters.AddWithValue("VoucherYear", birthDate);
               //cmd.Parameters.AddWithValue("UpdatedBy", VenName);
               con.Open();
               int k = cmd.ExecuteNonQuery();
               if (k != 0)
               {
                   MessageBox.Show("Record Inserted Succesfully into the Database");
                   //lblmsg.ForeColor = System.Drawing.Color.CornflowerBlue;
                   VendorName.Text = string.Empty;
                   ddlVoucherType.SelectedIndex = -1;
                   Date.Text = string.Empty;


               }
               con.Close();
           }
       }

推荐答案

杀了我,这是一个新发明,他的名字是WEB或www!
kill me, a new invention is here an his name is WEB or www !


这篇关于不上传多个文件只拍摄第一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆