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?

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 when url is long.                

            },
                    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); //Succesfull
        return url64;
    }

Any suggestions would be appreciated.

Related posts

Recent Viewed