7
Answers

file download

Photo of tordubey

tordubey

21y
1.9k
1
Hi, I'm using webclient in C# ASP.NET project to enable download of files to my web page visitors. However, files get copied to the server rather than the client machine. What could be the problem. Here is the sample that I've used: WebClient myWebClient = new WebClient(); myWebClient.DownloadFile("http://www.myweb.com/testfile.txt" ,"c:/test.txt"); The problem is that the test.txt gets copied to the C:\ drive of the server rather than the client machine.

Answers (7)

0
Photo of tordubey
NA 12 0 21y
You're right HREF would work, but I want to download multiple files after they have been selected by the user. I do not want the user to click on links repeatedly. Once they specify the folder, it should download all the files. Thanks, -rajeev (rdubey)
0
Photo of james
NA 1.1k 312.9k 21y
grrr.... stupid HTML interpreting forums... :) put this in an A tag href="\mydownload.zip"
0
Photo of james
NA 1.1k 312.9k 21y
Sorry, in my earlier post I meant that its running Server side, which sounds like its the case. As far as starting the download automatically, you should be able to do that directly with an HREF... click me and it shoudl prompt him to save that locally.
0
Photo of tordubey
NA 12 0 21y
The code is part of a web form. I intend to use it to automate the process of downloading multiple files by executing it in a loop after the web site user has selected all the files he wants to download. Once he presses the start download button and specifies the folder in which to copy the files on his computer, the files should get copied to his spcified folder. -rajeev (rdubey)
0
Photo of james
NA 1.1k 312.9k 21y
Is this code running as part of a Web Method? If so, thats running client side. That might cause the issue you're having. -James
0
Photo of tordubey
NA 12 0 21y
Hi James, thanks for the response. I tried this way too. The problem remains. The point is that the file gets downloaded to the machine on which the above code is located. What I mean is: Webserver1: hosting the above code ClientComputer1: Invoking the website hosted on Webserver1 having the above code. Result: The file gets copied to Webserver1 rather than the desired effect of downloading it to ClientComputer1. I hope I made it clear. Any clues on how to get right?
0
Photo of james
NA 1.1k 312.9k 21y
Here is a code sample of mine that works fine to download from a server... It may help /// /// Download the specified file from the uri /// /// The resource location of the file to be downloaded /// the name od the local file to save the download to private void GetFile(string uri, string file) { try { WebClient tmpwc = new WebClient(); tmpwc.DownloadFile(uri + file, file); } catch(System.Net.WebException) { // Download failed } catch(Exception ex) { throw(ex); } }