WebClient.DownloadFile

  • Thread starter Thread starter Rui Oliveira
  • Start date Start date
R

Rui Oliveira

WebClient.DownloadFile

I am using the WebClient.DownloadFile function to download a file from
server to a local client.

When I execute the below code, file is created in server and not in client.
WebClient wc = new WebClient();
wc.DownloadFile(strFileFrom, strFileTo);

What am I doing wrong?

Tks.
Rui Oliveira
 
WebClient.DownloadFile

I am using the WebClient.DownloadFile function to download a file from
server to a local client.

When I execute the below code, file is created in server and not in client..


What am I doing wrong?

Tks.
Rui Oliveira

Are you using WebClient's downloadfile method through an application
that resides on server? You must invoke method from a client that
should download data from a remote host(server).

Thanks,

Onur Güzel
 
Are you using WebClient's downloadfile method through an application
that resides on server? You must invoke method from a client that
should download data from a remote host(server).

Thanks,

Onur Güzel

If you are running asp.net and you want the browser to download it ,
then look at the following code. I found it online.If that does not
work, you will have to do something similar.

// Clear the content of the response

Response.ClearContent();

// LINE1: Add the file name and attachment, which will force the open/
cance/save dialog to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name);

// Add the file size into the response header
Response.AddHeader("Content-Length", file.Length.ToString());

// Set the ContentType

Response.ContentType = ReturnExtension(file.Extension.ToLower());

// Write the file into the response (TransmitFile is for ASP.NET 2.0.
In ASP.NET 1.1 you have to use WriteFile instead)

Response.TransmitFile(file.FullName);
 
WebClient.DownloadFile

I am using the WebClient.DownloadFile function to download a file from
server to a local client.

When I execute the below code, file is created in server and not in client..


What am I doing wrong?

Tks.
Rui Oliveira

where r u executing it?
 
I have an asp.net application that runs in IIS.
I have files in IIS server, and I want from IE client download and save
these files in the local client.
Rui
 
I have an asp.net application that runs in IIS.
I have files in IIS server, and I want from IE client download and save
these files in the local client.
Rui
 
(note that you won't be able to choose the destination; the user has to
accept the file and location)

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top