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")

EPPlus ile oluşturulmuş excel dosyanın download edilmesi

pck EPPlus package nesnesidir. Aşağıdaki kod try-catch bloğu içerisinde olmalıdır ve ThreadAbortException hatası kesinlikle handle edilmelidir.

            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)

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

            End Using

LinkWithin

Related Posts Plugin for WordPress, Blogger...