• This repository has been archived on 02/Oct/2024
  • Stars
    star
    294
  • Rank 141,269 (Top 3 %)
  • Language
    C#
  • License
    Other
  • Created about 9 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OneDrive SDK for C#! https://dev.onedrive.com

OneDrive SDK for CSharp

Build status

Integrate the OneDrive API into your C# project!

The OneDrive SDK is built as a Portable Class Library and targets the following frameworks:

  • .NET 4.5.1
  • .NET for Windows Store apps
  • Windows Phone 8.1 and higher

Azure Active Directory authentication is available for:

  • Windows Forms apps
  • UWP apps
  • Windows 8.1 apps

Installation via Nuget

To install the OneDrive SDK via NuGet

  • Search for Microsoft.OneDriveSDK in the NuGet Library, or
  • Type Install-Package Microsoft.OneDriveSDK into the Package Manager Console.

Getting started

1. Register your application

Register your application for OneDrive by following these steps.

2. Setting your application Id and scopes

Your app must requests permissions in order to access a user's OneDrive. To do this, specify your app ID and scopes, or permission level. For more information, see Authentication scopes.

3. Getting an authenticated OneDriveClient object

You must get a OneDriveClient object in order for your app to make requests to the service, but first you must have an instance of an object that implements IAuthenticationProvider in Microsoft.Graph.Core. An example of such an imlementation can be found MSA Auth Adapter repository. You should create the IAuthenticationProvider, authenticate using AuthenticateUserAsync(), and then create a OneDriveClient using the auth provider as a constructor argument. You must also provide the ClientId of your app, the return URL you have specified for your app, and the base URL for the API. Below is a sample of that pattern for authentication on the OneDrive service.

var msaAuthProvider = new myAuthProvider(
    myClientId,
    "https://login.live.com/oauth20_desktop.srf",
    { "onedrive.readonly", "wl.signin" });
await msaAuthProvider.AuthenticateUserAsync();
var oneDriveClient = new OneDriveClient("https://api.onedrive.com/v1.0", msaAuthProvider);

After that, you will be able to use the oneDriveClient object to make calls to the service. For more information, see Authenticate your C# app for OneDrive.

4. Making requests to the service

Once you have a OneDriveClient that is authenticated you can begin to make calls against the service. The requests against the service look like OneDrive's REST API.

To retrieve a user's drive:

    var drive = await oneDriveClient
                          .Drive
                          .Request()
                          .GetAsync();

GetAsync will return a Drive object on success and throw a Microsoft.Graph.ServiceException on error.

To get the current user's root folder of their drive:

    var rootItem = await oneDriveClient
                             .Drive
                             .Root
                             .Request()
                             .GetAsync();

GetAsync will return an Item object on success and throw a Microsoft.Graph.ServiceException on error.

For a general overview of how the SDK is designed, see overview.

The following sample applications are also available:

To run the OneDrivePhotoBrowser sample app your machine will need to be configured for UWP app development and the project must be associated with the Windows Store.

Documentation and resources

Issues

To view or log issues, see issues.

Other resources

License

License

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

More Repositories

1

onedrive-sdk-python

OneDrive SDK for Python! https://dev.onedrive.com
Python
1,077
star
2

onedrive-api-docs

Official documentation for the OneDrive API
TypeScript
453
star
3

onedrive-sdk-android

OneDrive SDK for Android!
Java
148
star
4

onedrive-explorer-js

OneDrive sample application for JavaScript.
HTML
113
star
5

onedrive-sdk-ios

OneDrive SDK for iOS
Objective-C
101
star
6

onedrive-picker-android

Sample application for OneDrive file picker SDK for Android
Java
100
star
7

onedrive-sample-apibrowser-dotnet

C#
77
star
8

onedrive-explorer-win

OneDrive API Explorer sample code for Windows / C#
64
star
9

samples

Contains samples, scenarios, and guidance for integrating with OneDrive and SharePoint drives, drive items, and files.
C#
56
star
10

onedrive-explorer-android

OneDrive Explorer for Phone and Tablets!
Java
55
star
11

apidoctor

Application for validating API documentation and generating test cases
C#
40
star
12

onedrive-community-samples

Repository for community samples in OneDrive GitHub organization.
34
star
13

onedrive-admin-scripts

OneDrive Scripts for Administrators
PowerShell
31
star
14

o365-markdown-file-handler-v2

File handler for Office 365 to enable previewing and viewing markdown documents
C#
27
star
15

onedrive-texteditor-js

Simple single-page JavaScript app for editing text files
JavaScript
26
star
16

markdown-scanner

Application for scanning markdown documentation and generating test cases for APIs.
C#
23
star
17

onedrive-sdk-dotnet-msa-auth-adapter

C#
23
star
18

onedrive-webhooks-aspnet

Sample ASP.NET MVC application that receives webhooks from OneDrive and OneDrive for Business
JavaScript
19
star
19

graph-sample-photobrowser-uwp

The Microsoft OneDrive Graph Photo Browser sample is a Windows Universal app that uses the OneDrive SDK for C#/.NET. The sample app displays only items that are images from a user's OneDrive. Note that this sample does not work with OneDrive for Business.
C#
17
star
20

onedrive-sample-sync-ios

OneDrive iOS Sync Sample App
Swift
13
star
21

onedrive-data-robot-azure-function

Sample code using Azure Functions with OneDrive webhooks
C#
11
star
22

onedrive-sample-photobrowser-uwp

C#
10
star
23

document-library-audio-transcription-robot-sample

Sample from Ignite 2017 talk, that uses the Speech API to transcribe audio files in a document library
C#
4
star
24

file-browser-demo

JavaScript
3
star
25

.github

Default Community Health Files for the OneDrive organization on GitHub
1
star