Rakesh R Surve[RST] Ответов: 1

Не загружайте несколько файлов только первый взятый файл


Мой первый файл только выбирается. но в
HttpPostedFile 
отображается второе имя файла.

Что я уже пробовал:

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();
           }
       }

Karthik_Mahalingam

что такое граф
filecount = SelectFile.PostedFiles.Рассчитывать();

Rakesh R Surve[RST]

filecount = строка,
selectFile= имя элемента управления загрузкой файла,
cand count дает мне 5, Когда я выбираю 5 файлов для загрузки

Karthik_Mahalingam

Ящик для сообщений.Показать в веб-приложении ?

Rakesh R Surve[RST]

Не получается, сэр...

Karthik_Mahalingam

это приложение для windows или веб ?

Rakesh R Surve[RST]

Asp.net веб-приложение...

Karthik_Mahalingam

как вы можете использовать " MessageBox.Show()" в веб-приложении?

Richard Deeming

Ваш код работает на сервере. Вы не можете использовать MessageBox.Show с сервера выводится сообщение клиенту.

Может быть появиться для работы при отладке сайта в Visual Studio. Но это только потому, что сервер и клиент являются одним и тем же компьютером в данном конкретном экземпляре.

Как только вы развернете свое приложение на реальном сервере, MessageBox.Show позвонить не получится.

В лучшем случае вы получите исключение, сообщающее вам, что вы не можете показать пользовательский интерфейс из неинтерактивного процесса.

В худшем случае сообщение всплывет на сервере, где его никто никогда не увидит, и ваш код будет висеть, ожидая, пока кто-то подтвердит тысячи сообщений на экране сервера.

Rakesh R Surve[RST]

Хорошо...

1 Ответов

Рейтинг:
0

mag13

убейте меня, здесь новое изобретение, и его зовут веб или www !