Click here to Skip to main content
13,140,231 members (47,755 online)
Rate this:
Please Sign up or sign in to vote.
Dear Experts,

I am doing an ASP.Net project, I need to send some datas and post form data through javascript to webservice....

Here is the below code of javascript.

function startUploading() {
        // get form data for POSTing
        //var vFD = document.getElementById('form-student-profile').getFormData(); // for FF3
        var vFD = new FormData(document.getElementById('form-student-profile'));
        // create XMLHttpRequest object, adding few event listeners, and POSTing our data
        var oXHR = new XMLHttpRequest();
        oXHR.upload.addEventListener('progress', uploadProgress, false);
        oXHR.addEventListener('load', uploadFinish, false);
        oXHR.addEventListener('error', uploadError, false);
        oXHR.addEventListener('abort', uploadAbort, false);'POST','../../Webservice.asmx/Img_Upload');
       // set inner timer
        oTimer = setInterval(doInnerUpdates, 300);

Here is the code in WebService

        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public void Img_Upload()
            HttpContext postedContext = HttpContext.Current;
            HttpPostedFile file = postedContext.Request.Files[0];
            string name = file.FileName;
            byte[] binaryWriteArray = new
            file.InputStream.Read(binaryWriteArray, 0,
            FileInfo file_Info = new FileInfo(file.FileName);
            string ext = file_Info.Extension;

            string file_Name = Guid.NewGuid().ToString() + "_" + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + ext;
            FileStream objfilestream = new FileStream(Server.MapPath("img//profilePIC//" + file_Name), FileMode.Create, FileAccess.ReadWrite);
            objfilestream.Write(binaryWriteArray, 0,
            SetVal.Profile_PIC = file_Name;

Here i can get the image file sucessfully, and i need to get some more string datas from that javascript function to this Webservice function....

Is there any method to get the file and datas ..??

please Help me..

Thanks and regards,

Posted 15-Apr-13 1:31am
Prasad Khandekar 15-Apr-13 16:06pm

Please read about multi-part form data. Please have a look at this ( JQuery plugin or


1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I found your question looking for some help myself with something very similar.
You can easily add some more values to your POST.

In you javascript you can simply add:
vFD.append("key1", "somevalue");

and in the codebehind:
string value = postedContext.Request["key1"];

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 27 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100