0

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

2
  • here ajax doesn't pass the image files so you could retireve the file by normally Commented Jul 20, 2017 at 5:22
  • var image = $("#ContentPlaceHolder1_FileUpload1").val(); is this right way to pass the imge Commented Jul 20, 2017 at 5:26

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.