Bilawal Niaz

Bilawal Niaz

  • NA
  • 110
  • 16.5k

How to upload multiple images at once in DB by using Asp.net

Nov 5 2016 2:55 AM
PageCode:
 
<asp:FileUpload AllowMultiple="true" ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Add Images" OnClick="Button1_Click" />
 
Backend Code:
 
protected void Button1_Click(object sender, EventArgs e)
{
BSL.Image obj = new BSL.Image();
obj.Image1 = FileUpload1.FileName;
obj.Image2 = FileUpload1.FileName;
obj.Image3 = FileUpload1.FileName;
obj.Image4 = FileUpload1.FileName;
obj.Image5 = FileUpload1.FileName;
Random r = new Random();
long s = r.Next(10000, 200000);
obj.Image1 = s + FileUpload1.FileName;
obj.Image2 = s + FileUpload1.FileName;
obj.Image3 = s + FileUpload1.FileName;
obj.Image4 = s + FileUpload1.FileName;
obj.Image5 = s + FileUpload1.FileName;
string path = Server.MapPath(@"Images/New/" + s + FileUpload1.FileName);
FileUpload1.SaveAs(path);
PictureHandler obj2 = new PictureHandler();
obj2.AddImage(obj);
}
 

Answers (12)