I'm trying to download a file from my local computer, which is in a library sharepoint. I'm using this function :

                siteURL += "?NoRedirect=true";
                System.Net.WebClient _WebClient = new System.Net.WebClient();
                _WebClient.Credentials = CredentialCache.DefaultCredentials;
                // Downloads the resource with the specified URI to a local file.
                _WebClient.DownloadFile(siteURL, saveName);
        catch (Exception _Exception)
            // Error
            //MessageBox.Show("Error In Downloading");

and where saveName is equal to : string pathToDesktop = Environment.ExpandEnvironmentVariables("%USERPROFILE%") + @"\Desktop" + "\Export-" + filenamexls;

The thing is that i want to download the file on my computer and not on the server. But I don't know how to do this.

Can someone help me on this one ?

  • Are you trying to push from server a file to client computer ?
    – Steve B
    Commented Jun 4, 2012 at 14:31
  • Where is the code you're writing running? Commented Jun 4, 2012 at 16:20
  • Does SiteURL point to a specific file or the site itself? Are you getting an error - if so, what?
    – Dave Wise
    Commented Jun 4, 2012 at 16:22
  • @SteveB Yes that's exactly what i want to do. My code is running on the server Commented Jun 4, 2012 at 16:22
  • SiteURL is pointing to a specific site, and i'm not getting any error, the only problem is that the file is downloaded into the desktop's server and not the one of my computer Commented Jun 4, 2012 at 16:24

2 Answers 2


You can't push the file to the client from the server. The server side has no knowledge of the client side. You have to write a client application, that will pull the file.

First, you'll have to know the url of the file.

Then, a simple

var wc = new WebClient();
wc.UseDefaultCredentials = true;
wc.DownloadFile(targetFile, @"c:\temp\myfile.txt");

would do the job (assuming windows authentication and access to the file granted).


If your client code is running on server which means that request is being sent from server and your file will eventually downloaded on server. I would recommend you to write a code which runs on your computer and download the file from Server. You can Lists.asmx or OOTB Web Service to download the file from the Server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.