SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question
Are you trying to push from server a file to client computer ? – Steve B Jun 4 '12 at 14:31
Where is the code you're writing running? – Per Jakobsen Jun 4 '12 at 16:20
Does SiteURL point to a specific file or the site itself? Are you getting an error - if so, what? – Dave Wise Jun 4 '12 at 16:22
@SteveB Yes that's exactly what i want to do. My code is running on the server – Thoma Bigueres Jun 4 '12 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 – Thoma Bigueres Jun 4 '12 at 16:24
up vote 5 down vote accepted

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).

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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