Thursday, June 16, 2011

Download File from URL, Download Document from SharePoint library using c#


public void DownloadFileFromSite(string siteURL, string saveName  )
{
    try
    {
        System.Net.WebClient _WebClient = new System.Net.WebClient();
        // Downloads the resource with the specified URI to a local file.
        _WebClient.DownloadFile(siteURL, saveName);
}
    catch (Exception _Exception)
    {
        // Error
       MessageBox.Show("Error In Downloading");
    }
}

5 comments:

  1. this returns 401 unauthorised

    ReplyDelete
  2. http://stackoverflow.com/questions/1443617/407-authentication-required-no-challenge-sent/1482442#1482442

    ReplyDelete
  3. http://blogs.realdolmen.com/experts/2010/11/08/sharepoint-401-unauthorized-downloading-infopath-file-with-webclient-downloadfile/

    ReplyDelete
  4. http://stackoverflow.com/questions/8609211/download-file-from-given-url

    ReplyDelete
  5. private static bool DownloadFileFromSite(string siteURL, string saveName)
    {
    try
    {
    // Downloads the resource with the specified URI to a local file
    System.Net.WebClient _WebClient = new System.Net.WebClient();
    _WebClient.UseDefaultCredentials = true;
    _WebClient.DownloadFile(siteURL, saveName);
    }
    catch (Exception ex)
    {
    Console.WriteLine("Error downloading latest spreadsheet from Sharepoint:" + ex.Message + ex.StackTrace);
    return false;
    }

    return true;
    }

    ReplyDelete

Thank you for Commenting Will reply soon ......

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...