Click here to Skip to main content
14,969,930 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have all ready pdf file in a folder i want to get this pdf file using web services and show on it html using java script

What I have tried:

var dataString = JSON.stringify({

//accountID: '309'
});

$.ajax({
type: "GET",
contentType: "application/json ",
url: "http://localhost:61185/WebService.asmx/DownloadFile",
data: dataString,
processData: true,
dataType: "json",
success: function (response) {
var reader = new FileReader();
reader.readAsArrayBuffer(response.d);
reader.onloadend = function (evt) {
console.log("read success");
console.log(new Uint8Array(evt.target.result));
};
},
error: function (a, b, c) {
alert('file error')
}
});


[WebMethod()]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public byte[] DownloadFile()
{
byte[] filebytes = null;
// using (FileStream fs = File.OpenRead("APBoard_ReportCard\\APBoard_ReportCard_3844-13_4"))
string pdffile = Server.MapPath("~/APBoard_ReportCard/APBoard_ReportCard_3844-13_4.pdf");
FileStream fs=new FileStream(pdffile, FileMode.Open, FileAccess.Read);
// {
filebytes = new byte[fs.Length];
fs.Read(filebytes, (int)0, (int)fs.Length);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(filebytes.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, filebytes);
byte[] jsonString =Encoding.Default.GetBytes(ms.ToString());
ms.Close();
return jsonString;
// }
//return filebytes;
//return jsonString;
}
Posted

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900