如何将文件发送到浏览器以便用户可以打开/保存?

时间:2017-10-13 09:32:19

标签: vb.net asynchronous webclient httpresponse webclient-download

点击它时我有一个按钮我必须调用异步方法,该方法必须从共享路径下载数据并提示用户保存/打开。

   **ButtonClick Method**
    Private Sub btnDownload_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.ServerClick
    Dim obj As New delAsyncMethodCaller(AddressOf downloadReport) As Byte()
    Dim iAr As IAsyncResult = obj.BeginInvoke(New AsyncCallback(AddressOf AsyncComplete), Nothing)
    End Sub

    Public Function downloadReport() As Byte()
    Dim strFileName As String = "Test.txt"
    Dim FileName As String = "Test.txt"
    Dim strDestinationPath As String ="\\appsupld\Uploads\OfficeAutomation\APR\Downloads\"
    Dim myStringWebResource As String = Nothing
    Dim myWebClient As New WebClient()
    myStringWebResource = strDestinationPath + strFileName
    Dim data As Byte() = myWebClient.DownloadData(myStringWebResource)
    return data

    End Function

    Public Sub AsyncComplete(iAr As IAsyncResult)
    Dim ar As AsyncResult = DirectCast(iAr, AsyncResult)
    Dim del As delAsyncMethodCaller = DirectCast(ar.AsyncDelegate, delAsyncMethodCaller)
    Dim result As Integer = del.EndInvoke(iAr)
End Sub

这段代码正在将文件下载到我自动指定的路径中。如何获得提示以便用户可以打开/保存它。

当用户点击下载时,操作应该异步完成,以便用户可以处理其他事情,一旦异步操作完成,他应该提供一个pop来打开/保存文档?

我无法使用Response.binarywrite(),因为响应无效,因为下载方法在异步调用后结束

0 个答案:

没有答案
相关问题