none
Using WebClient to download a file to the default dowload folder RRS feed

  • Question

  • I am writing a web application which allows a client to download a file and I have tried the WebClient Class for this purpose. What I would like to do is that when a file is downloaded the client receives it in their default "download folder". I am actually using the DownloadFile(String, String) overload and here I need to specify a location to get the file. Is there a way to achieve my goal so the client receives the file in his/her default download folder automatically?

    Best regards,
    Jorge Maldonado


    Best regards, JORGE MALDONADO

    Monday, March 31, 2014 10:33 PM

Answers

  • Hi Jorge,

    >I am writing a web application which allows a client to download a file and I have tried the WebClient Class for this purpose. What I would like to do is that when a file is downloaded the client receives it in their default "download folder".

    Web app is written by you, then you want to use WebClient to download file from web app in client app. Is it right?

    >Is there a way to achieve my goal so the client receives the file in his/her default download folder automatically?

    You want to download files from web app and save them into the default directory. You can use configuration file to save your default directory. I assume you are using WinForm as your client app. Add application configuration File in solution if you cannot see app.config. Add the following code in that file.

    <?xml version="1.0" encoding="utf-8" ?>
    
    <configuration>
    
      <appSettings>
    
        <add key="DefaultSavePath" value="d:\FilesFromWeb"/>
    
      </appSettings>
    
    </configuration>
    

    Add “System.Configuration.dll” assembly to your project. Use the following code to find the default save directory.

     

     System.Net.WebClient webclient = new System.Net.WebClient();
    
                webclient.DownloadFile("url address", Helper.DefaultDirectory);
    

    Hope useful.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 2, 2014 2:58 AM
    Moderator