Reputation: 3
jquery code
$(document).ready(function () {
$("#ContentPlaceHolder1_btnsubmit").click(function () {
var name = $("#ContentPlaceHolder1_txtname").val();
var course = $("#ContentPlaceHolder1_txtcourse").val();
var qualififcation = $("#ContentPlaceHolder1_txtqualification").val();
var company = $("#ContentPlaceHolder1_txtcomp").val();
var salary = $("#ContentPlaceHolder1_txtsal").val();
var role = $("#ContentPlaceHolder1_txtrole").val();
var description = $("#ContentPlaceHolder1_txtdesc").val();
var status = $("#ContentPlaceHolder1_ddstatus").val();
var image = $("#ContentPlaceHolder1_FileUpload1").val();
var url = "ajaxhandler.aspx?taskname=insertstudent";
$.post(url,
{
name: name, course: course, qualififcation: qualififcation, company: company, salary: salary,
role: role, description: description, status: status, image: image
},
function (data, status) {
if (status == "success") {
alert("student inserted");
}
}
)
});
});
ajaxhandler page code
int image = Convert.ToInt32( Request.Form["image"]);
int a = BLL.studentbll.insertstudent(name,course,qualification,company,salary,role,description, status);
if (image>0 )
{
string ext = System.IO.Path.GetExtension(image.FileName);
image.SaveAs(Server.MapPath("images\\" + Convert.ToString(a) + ".jpg"));
}
seems error while storing image image.filename is inaccessible How to save image in a folder in asp.net using ajax or jquery
Upvotes: 0
Views: 1328
Reputation: 406
Here ajax doesn't pass the image files so you could retrieve the file by normally in ajax handler
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
Here is the reference site link:
http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html
Upvotes: 1