I am calling a web service which returns a byte[] of an attachment. I then convert the byte[] to base64 string and return results to the client. i Then want to display this returned string in the browser (IE is necessary). i am getting file not found because i believe IE has URL length limit of a little over 2000. What are my options of displaying the attachment returned? If there's no way to display it, how can i prompt user to save the attachment to a certain location using JavaScript?
Here's what I have:
//Ascx page
function retrieveAttachmentById() {
var DTO = { 'p_attachmentID': "123", 'p_itemId': "1" };
var url = "/_layouts/SharepointWebService/CustomService.asmx/GetAttachmentById";
$.ajax
({
type: "Post",
url: url,
data: JSON.stringify(DTO),
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function add(msg) {
var url = msg.d;
// display base64 content.
// window.location(url) doesn't work in IE when url is over 2047 characters.
},
error: function () { }
});
}
//CustomService.asmx
[WebMethod]
public string GetAttachmentById(int p_attachmentID, int p_itemId)
{
byte[] fileBuffer = //Call service passing in p_attachmentID and p_itemId
var url64 = Convert.ToBase64String(fileBuffer); //Successful
return url64;
}
Any suggestions would be appreciated.
You need to add the following entry in your web.config. I believe thats the max value you can have for jsonSerialization
<configuration>
...
...
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647"/>
</webServices>
</scripting>
</system.web.extensions>
<system.webServer>
...
...
</configuration>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.