Asp.Net de foreach ile dönerek çoklu dosya yükleme.
ASPX:
1 |
<asp:FileUpload ID="FileUpload1" AllowMultiple="true" CssClass="form-control" runat="server" /> |
AllowMultiple=”true” sunucuda çalışmazsa multiple=”multiple” ekleyiniz.
CS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
string f1 = ""; String path = Server.MapPath("~/uploads/"); for (int j = 0; j < Request.Files.Count; j++) { HttpPostedFile File = Request.Files[j]; if (File.ContentLength > 0) { String fileExtension = System.IO.Path.GetExtension(File.FileName).ToLower(); String[] allowedExtensions = { ".png", ".jpg", ".jpeg", ".pdf", ".xls", ".xlsx", ".zip", ".rar", ".doc", ".docx" }; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { f1 = "DO_" + Request["i"].PadLeft(5, '0') + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss").Replace(".", "") + System.IO.Path.GetExtension(File.FileName).ToLower(); break; } } FileUpload1.PostedFile.SaveAs(path + f1); //"INSERT INTO TVFotos (BA_ID,FPath,Aciklama) VALUES (" + Request["i"] + ",'" + f1 + "','" + File.FileName + "')" } } dtg_kayitlar.DataBind(); lbl_durum.Text = "OK, Dosyalar Kaydedildi"; |
Tek dosya yükleme ve indirmenin detayları için bir önceki yazımız;