Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

How to upload multiple files using ajaxfileupload in asp.net to database?

$
0
0

Hi guys! I'v been trying to upload six images using ajaxfileupload in asp.net to MSSQL server but it always save only one image. 

Here is the aspx code:

<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell"><strong>Thumbnail Images:
</strong></div>
<div class="divTableCell">
<asp:AjaxFileUpload ID="itemFileUpload3"
runat="server"
OnUploadComplete="itemImage3OnUpload"
MaximumNumberOfFiles="10" Width="420px"/>
<p id="itemImage3Validate"></p>
</div>
</div>
</div>

And here is the aspx.cs code:

protected void itemImage3OnUpload(object sender, AjaxFileUploadEventArgs
e)
{

string filename = e.FileName;
Session["PicturePath3"] = filename;
if (itemType1.Checked)
{
itemFileUpload3.SaveAs(Server.MapPath("~/Images/Sub Images/") +
filename);
}
else if (itemType2.Checked)
{
itemFileUpload3.SaveAs(Server.MapPath("~/Images/Sub Images/") +
filename);
}

}

protected void itemSaveButton_Click(object sender, EventArgs e)
{

try
{

string itemThumbImage = Session["PicturePath3"].ToString();


int itemInstrumentID =
ConnectionClassGuitarItems.GetItemIDByNameAndModel
(item_brandId,item_model);

var subImg = new thumbnailImage
{
instrumentId = itemInstrumentID,
subimages = itemThumbImage
};


ConnectionClassGuitarItems.AddThumnailImage(subImg);
ScriptManager.RegisterStartupScript(this.Page,this.GetType()
, "msgboxScc", "btnClickSuccess();", true);

ClearTextFields2();

}
catch (Exception)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType()
, "msgboxErr", "btnClickFail();", true);
}


}

And then I will add my images using this code:

public static void AddThumnailImage(thumbnailImage subImg)
{
using (MusicStoreDBEntities obj = new MusicStoreDBEntities())
{

obj.thumbnailImages.Add(subImg);
obj.SaveChanges();
}
}


Viewing all articles
Browse latest Browse all 5678

Trending Articles