0

I have a few files in a document library which were never checked-in. I have that list of files available through the document library settings page or in c# using SPDocumentLibrary.CheckedOutFiles

Is there a way that I can download those files without taking their ownership via C#.

Saksham
  • 9,037
  • 7
  • 45
  • 73

1 Answers1

0

You don't take ownership if you download files from SharePoint. If you're using the SharePoint CSOM API, you're code look like this:

using (var clientContext = new ClientContext(url))
        {
            clientContext.Credentials = creds;

            var list = clientContext.Web.Lists.GetByTitle(listTitle);
            var listItem = list.GetItemById(listItemId);
            clientContext.Load(list);
            clientContext.Load(listItem, i => i.File);
            clientContext.ExecuteQuery();

            var fileRef = listItem.File.ServerRelativeUrl;
            var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef);
            var fileName = Path.Combine(filePath,(string)listItem.File.Name);
            using (var fileStream = System.IO.File.Create(fileName))
            {

                fileInfo.Stream.CopyTo(fileStream);
            }
        }
hbulens
  • 1,872
  • 3
  • 24
  • 45