Note that there are some explanatory texts on larger screens.

plurals
  1. POhow i upload file using jquery ajax and wcf rest service
    primarykey
    data
    text
    <pre><code> Hello All, how i can upload file using jquery ajax i am trying to send this parameter to wcf rest service but its not working. here is the ajax code where i am passing file name and file object. enter code here $.ajax({ url: "http://localhost:1340/b/SaveProjectDocument/" + file.name + "/" + file, data: null, type: "POST", contentType: "application/javascript", dataType: "jsonp", error: function () { alert("Failed!"); }, success: function () { $("#divLoadingEdit").hide(); } }); </code></pre> <p>here is the wcf code where i am retrieving data from jquery and file object in a string and convert into stream. using below code i can store file but the byte are storing not correct. please advice me what is wrong with it asap.</p> <pre><code>[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "SaveProjectDocument/{filename}/{fileContents}")] public void SaveProjectDocument(string filename, string fileContents) { try { //converting string into stream. //byte[] byteArray = Encoding.UTF8.GetBytes(fileContents); byte[] byteArray = Encoding.ASCII.GetBytes(fileContents); MemoryStream stream = new MemoryStream(byteArray); //reading stream and assign new memory to byte array. byte[] buffer = new byte[stream.Length]; int count = 0; FileStream fileToupload = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Files/") + filename, FileMode.Create, FileAccess.ReadWrite); while (count &lt; stream.Length) { buffer[count++] = Convert.ToByte(stream.ReadByte()); } fileToupload.Write(buffer, 0, buffer.Length); fileToupload.Close(); fileToupload.Dispose(); } catch (Exception ex) {`enter code here` ///return 0; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload