Problems with webclient.downloadfile and variable

0

Good morning. I would like to see the possibility to help me with a problem I have with webclient.downloadfile. It happens that I need to download a PDF file from another server connected internally to my asp server, the problem occurs when the destination url uses it in a variable. When I occupy the WebClient.DownloadFileAsync I get the following error:

  

Appointment in block   An asynchronous module or controller completed while an asynchronous operation was still pending.

When I use WebClient.DownloadFile I get a 404 error on the remote server.

I leave the code I use.

WebClient client = new WebClient();
        Uri ur = new Uri("http://192.168.0.238" + rutaPDF);

        client.DownloadProgressChanged += WebClientDownloadProgressChanged;
        client.DownloadDataCompleted += WebClientDownloadCompleted;
        client.DownloadFileAsync(ur, @"C:\inetpub\wwwroot\centauro\pdf\pdf" + idEmp + ".pdf");

The variable "pathPDF" contains the rest of the path including the file (/folder1/folder2/FilePDF.pdf) and that changes depending on which file you want to download, therefore I must use a variable if or if.

It is important to mention that when I write the complete URL as a parameter of webclient.downloadfile, it works correctly and downloads the file, the problem occurs when that url is used as a variable.

I hope you can help me, since I've been searching the internet for days and doing unsuccessful tests.

Greetings to all and thank you.

    
asked by Israel Sebastián 09.02.2017 в 13:36
source

0 answers