简体   繁体   中英

Downloading from Sharepoint Document Library

Goal: Download documents from a Sharepoint 2010 Document Library using C#

I've searched and found many questions/resources regarding how to download documents to a local disk from a Sharepoint Document Library. I've so far been unable to successfully implement a solution.

For the sake of discussion, my document library is located at the following link: http://server.domain.com/sites/CompanyLocation/dprtmnts/DepartmentName/MyLibraryName/Forms/AllItems.aspx

Within this document library are two folders, each containing a number of documents. I desire to retrieve a list of these documents (in each folder) and have the ability to download/open a document on command.

Things I've tried:

  1. The linked post from this comment: https://sharepoint.stackexchange.com/a/105923

The linked post ( https://stackoverflow.com/a/21056425/2480558 ) offers a solution for both downloading and uploading. I only need to download, so I tried that. This solution gives me a Microsoft.SharePoint.Client.ServerObjectNullReferenceException. There are no instructions on what the url, listTitle, or listItemId need to be, so I'm probably doing something wrong... it doesn't appear to be getting any files.

I also tried the first blog post on that answer that points to using a package from bendsoft. Apparently that package is a paid package, and it's quite expensive.. I can't go that route.

  1. Another answer: https://stackoverflow.com/a/53733630/2480558

This gives me the following exception: (actual server edited out of exception)

Microsoft.SharePoint.Client.ClientRequestException: 'The IDCRL response header from server 'http://server.domain.com/' is not valid. The response header value is 'NTLM'. The response status code is 'Unauthorized'. 
  1. This solution: https://stackoverflow.com/a/15602003/2480558

Honestly, I don't even remember why that one didn't work.

If anyone has something that might help me get on the right path... I'm not familiar with making web requests and web authorization, or anything of that nature.

If you use the example that you found at https://stackoverflow.com/a/53733630/2480558 , but you have to adapt it for your local SharePoint server, since that code is logging in to SharePoint Online.

In the public void Connect() definition, replace the line
clientContext.Credentials = new SharePointOnlineCredentials(UserName, securePassword);
with this instead:
clientContext.Credentials = new NetworkCredential(UserName, securePassword, "putYourADDomainNameHere");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM