0

I have a gridview and a download button for each and every row. the page objective is to list out all the records related to physical files, and when download button clicked it should download and open the downloaded file. the files are in 'pdf' format.

The page is coded and everything is going fine. I want to rebind the gridview when the file got downloaded. but after download, the rest of the page's execution or lifecycle is not being done.

it seems the issue is with page handlers. I tried searching over the internet, but unfortunately no solution found. I request you experts please help me in this issue. and my code is like below.

Dim outputStream As FileStream = New FileStream((Server.MapPath("../ScannedDoc") + ("\" + fileName)), FileMode.Create) reqFTP = CType(FtpWebRequest.Create(New Uri(DataDirectory + "InternalDocuments/" + folderName + "/" + fileName)), FtpWebRequest)

                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
                reqFTP.UseBinary = True
                reqFTP.Credentials = New NetworkCredential(uid, pwd)
                Dim ftpresponse As FtpWebResponse = CType(reqFTP.GetResponse, FtpWebResponse)

                Dim ftpStream As Stream = ftpresponse.GetResponseStream
                Dim cl As Long = ftpresponse.ContentLength
                Dim bufferSize As Integer = 2048
                Dim readCount As Integer
                Dim buffer() As Byte = New Byte((bufferSize) - 1) {}
                readCount = ftpStream.Read(buffer, 0, bufferSize)

                While (readCount > 0)
                    outputStream.Write(buffer, 0, readCount)
                    readCount = ftpStream.Read(buffer, 0, bufferSize)

                End While
                ftpStream.Close()
                outputStream.Close()
                ftpresponse.Close()

                Dim responseFile As String = Server.MapPath("../ScannedDoc") + ("\\" + fileName)
                Response.ContentType = "application/pdf"
                Response.AppendHeader("Content-Disposition", ("attachment; filename=" + fileName))
                Response.TransmitFile(responseFile)
                Response.Flush()

                File.Delete(responseFile)

Thanks in advance
Sri.

4

1 回答 1

2

这种行为是设计使然。将下载按钮指向传输文件的单独页面或处理程序,这样您就不必离开当前页面/请求。

于 2013-06-07T03:57:58.897 回答