Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

        try
        {
                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
show 2 more comments

2 Answers 2

up vote 4 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
add comment

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
add comment

Your Answer

 
discard

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.