Google Mobile Ads

Monday, August 22, 2016

JQuery.FileDownload plugin'i ile dosya download edilmesi

JQuery.FileDownload (https://github.com/johnculviner/jquery.fileDownload) plugin'ini düzgün çalıştırabilmek için Set-Cookie ve Cache-Control header larının code behind kısmında eklenmesi gerekiyor.

Download.aspx.vb

           Response.Clear()
            Dim timestamp As String = Request.QueryString("timestamp")
            timestamp = CodeHelper.CheckClientContent(timestamp)
            Dim fileName As String = "File_" & timestamp & ".xlsx"

            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            Response.AddHeader("Content-Disposition""attachment;filename=" & fileName)

                   Response.AddHeader("Set-Cookie", "fileDownload=true; path=/")
            Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate")


            Using myMemoryStream As New MemoryStream
                pck.SaveAs(myMemoryStream)
                myMemoryStream.WriteTo(Response.OutputStream)
                Response.Flush()
                Response.End()
            End Using



Javascript tarafı

    $find("mpePleaseWait").show();

    var timestamp = $.now();

    $.fileDownload(encodeURI("Download.aspx?ExportType=PSM&timestamp=" + timestamp), {
        successCallback: function (url) {
            $find("mpePleaseWait").hide();
        },
        failCallback: function (responseHtml, url) {

            $find("mpePleaseWait").hide();
        }
    });

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...