Arlodotexe / OwlCore.Storage.OneDrive

An implementation of OwlCore.Storage that allows access to OneDrive

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OwlCore.Storage.OneDrive Version

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.

Install

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

Usage

Before you begin, obtain an instance of a GraphServiceClient from either:

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();
        // ... 
    }
}

Financing

We accept donations here and here, and we do not have any active bug bounties.

Versioning

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.

License

All OwlCore code is licensed under the MIT License. OwlCore is licensed under the MIT License. See the LICENSE file for more details.

About

An implementation of OwlCore.Storage that allows access to OneDrive


Languages

Language:C# 100.0%