An implementation of OwlCore.Storage that uses MSGraph to access OneDrive.
NOTE: This library is read-only for now, and doesn't support modifying folder contents. Check back later, or feel free to submit a PR.
Published releases are available on NuGet. To install, run the following command in the Package Manager Console.
PM> Install-Package OwlCore.Storage.OneDrive
Or using dotnet
> dotnet add package OwlCore.Storage.OneDrive
Before you begin, obtain an instance of a GraphServiceClient from either:
- The official
Microsoft.Graphlibraries. - The
CommunityToolkit.Graphhelpers. Recommended for apps in the Microsoft Store.
var graphClient = CreateGraphClient(...);
// Then, get the desired drive to work in.
var drive = await graphClient.Me.Drive.GetAsync();
// To get folder from a known folder Id:
var knownFolderId = "someId";
var driveItem = await graphClient.Drives[drives.Id].Items[knownFolderId].GetAsync();
// Or, to get user's root folder in OneDrive:
var driveItem = await graphClient.Drives[drive.Id].Root.GetAsync();
// Pass starting item to a new OneDrive folder
var oneDrive = new OneDriveFolder(graphClient, driveItem);
// Interact with OneDrive via the storage abstraction.
// Extension methods GetFilesAsync and GetFolderAsync also available.
await foreach (var item in oneDrive.GetItemsAsync(StorableType.All))
{
if (item is IFile file)
{
using var stream = await file.OpenStreamAsync();
// ...
}
if (item is IFolder folder)
{
var root = await folder.GetRootAsync();
// ...
}
}We accept donations here and here, and we do not have any active bug bounties.
Version numbering follows the Semantic versioning approach. However, if the major version is 0, the code is considered alpha and breaking changes may occur as a minor update.
All OwlCore code is licensed under the MIT License. OwlCore is licensed under the MIT License. See the LICENSE file for more details.