Skip to content

Instantly share code, notes, and snippets.

@chakkaradeep
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chakkaradeep/9ee19af313dfc8a3bb05 to your computer and use it in GitHub Desktop.
Save chakkaradeep/9ee19af313dfc8a3bb05 to your computer and use it in GitHub Desktop.
Office 365 API My Files - Get All Files from a Folder
public static async Task<ObservableCollection<MyFile>> GetMyFiles(string strFolderName)
{
//MyFile is the business object
ObservableCollection<MyFile> myFilesList = new ObservableCollection<MyFile>();
//get the files from the folder
var filesResults = await _spFilesClient.Files[strFolderName].ToFolder().Children.ExecuteAsync();
//get the results from current page
var files = filesResults.CurrentPage.OfType<Microsoft.Office365.SharePoint.File>().ToList();
//enumerate the results and build the business object
foreach (var file in files)
{
MyFile myFile = new MyFile();
myFile.Id = file.Id;
myFile.Name = file.Name;
myFile.ContentStream = await GetFileContent(file.Id);
myFilesList.Add(myFile);
}
//return the business object collection
return myFilesList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment