Cevaplar
-
standart 5 adet fileupload varmı bilmiyorum ancak genelde bu durumlarda dinamik olarak istediği sayıda fileupload eklettirerek file upload yaptırmak mantıklı. Daha sonrada bir for döngüsü ile bu fileupload nesnelerini kontrol eder seçili olanları upload yaparsın ki tekrar tekrar sayfa load olmaz.
Bir script ile dinamik file upload nesnesi ekletebilirsin.
Örnek Script :
<script type="text/javascript">
var say = 1;
function FpEkle() {
var UploadDiv = document.createElement('div');
UploadDiv.setAttribute('id', 'fu_' + say);
UploadDiv.innerHTML = '<input runat=server type=file /><input style="width: 100px" type=button value="Sil" onclick="sil(' + say + ');" />';
document.getElementById('fpmain').appendChild(UploadDiv);
say++;
} function sil(p) {
var c = document.getElementById('fu_' + p);
document.getElementById('fpmain').removeChild(c);
}
</script>
Bu scriptin çalıştırdığı HTML nesneleri :(Bir tane standart nesne vardır)
<input id="File1" runat=server type=file />
<input name="Button1" type="button" onclick="FpEkle()" value="Ekle"> <div id="fpmain"></div>
Buda nesnenin çalışması
protected void GonderBTN_Click(object sender, EventArgs e)
{
DosyaYukle();
}
void DosyaYukle()
{
HttpFileCollection dosyadizisi = Request.Files;
string uzanti = "";
string Resim = "";
//file upload da seçilen dosyaları atıyoruz
for (int i = 0; i < dosyadizisi.Count; i++)
{
HttpPostedFile dosya = dosyadizisi[i];
if (dosya.ContentLength > 0)
{
uzanti = System.IO.Path.GetExtension(dosya.FileName);
if (uzanti == ".jpg" || uzanti == ".jpeg" || uzanti == ".pdf" || uzanti == ".doc" || uzanti == ".docx")
{
Resim = "SoruResim_" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".jpg";
dosya.SaveAs(Server.MapPath("SoruImages") + "\\" + System.IO.Path.GetFileName(Resim));
//dosyalar tablosuna kayıt ediyoruz
DosyaKaydet(dosya.FileName.ToString(), Resim.ToString());
}
else
{
Response.Write("Geçersiz dosya formatı.Yanlızca .jpg, .jpeg, .pdf, .doc, .docx olabilir.");
}
}
}
}