Link to home
Start Free TrialLog in
Avatar of Simon Lacey
Simon Lacey

asked on

Async File Move in Web App .NET 4.0

I have an ASPX 4.0 page (with Async="true") that contains a user control with a Telerik RadGrid. Each row contains a button that causes an AJAX postback when clicked. When the user clicks the button I am trying to copy a PDF file from one server to this one. This works but the page is waiting until the entire file is completed before the postback completes. I am only wanting to "kickoff" the file copy when the user clicks the button then allow them to continue doing other things without having to wait for the large files to complete copying. I would have figured that doing this asynchronously would have worked but the AJAX panel is still waiting for the operation to complete.

Here is the relevant code that gets called when the user clicks the button:

Public Sub GetPDF(ByVal newFileLocationAndName As String, ByVal origFileLocationAndName As String)
                Dim myWebClient As WebClient = New WebClient
                AddHandler myWebClient.DownloadFileCompleted, AddressOf WebClient_DownloadFileCompleted
                myWebClient.DownloadFileAsync(New Uri(newFileLocationAndName), origFileLocationAndName)
End Sub

Private Sub WebClient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
                Dim wc As WebClient = DirectCast(sender, WebClient)
                RemoveHandler wc.DownloadFileCompleted, AddressOf WebClient_DownloadFileCompleted
                wc.Dispose()
End Sub
ASKER CERTIFIED SOLUTION
Avatar of deanvanrooyen
deanvanrooyen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial