Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to download a file by going through .aspx page and which returns a file like this

Response.Clear();
string content = Request.QueryString["param1"]+Request.QueryString["param2"]
Response.AddHeader("Content-Disposition", "attachment; filename=HelloWorld.txt");
Response.ContentType = "APPLICATION/OCTET-STREAM";
Response.AddHeader("Content-Length", content.Length.ToString());
Response.Write(content);
Response.End();

and in my main page:

$('#SaveFileBtn').click(function () {
$.ajax({
            async: true,
            type: "POST",
            url: 'CreateKeyFile.aspx',
            data:{param1:12,
                  param2:a},
            success: function (data) {// code to download the recieved data
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                alert("Error");
            }

        });

        return false;
    });

I tried to use an iframe.src and give it my url but I charging a url with a massive size and the use of iframe will limit it to 256 caraters only ! so how can I do it with SP javascript api or if it's possible with ajax ?

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.