No description, website, or topics provided.
C#
Latest commit c3fe2ad Nov 18, 2016 @cdmayer cdmayer update dependencies
Permalink
Failed to load latest commit information.
OneDrivePhotoBrowser update dependencies Nov 18, 2016
.gitignore Initial commit Jul 7, 2016
LICENSE.txt Initial commit Jul 7, 2016
OneDrivePhotoBrowser.sln Initial commit Jul 7, 2016
readme.md fix readme Jul 7, 2016

readme.md

OneDrive Photo Browser sample

The OneDrive 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.

Set up

Prerequisites

To run the sample, you will need:

  • Visual Studio 2013 or 2015, with Universal Windows App Development Tools Note: If you don't have Universal Windows App Development Tools installed, open Control Panel | Uninstall a program. Then right-click Microsoft Visual Studio and click Change. Select Modify and then choose Universal Windows App Development Tools. Click Update. For more info about setting up your machine for Universal Windows Platform development, see Build UWP apps with Visual Studio.
  • A Microsoft account and/or Azure Active Directory account with access to OneDrive for Business
  • Knowledge of Windows Universal app development

Download the sample

  1. Download the sample from GitHub by choosing Clone in Desktop or Download Zip.
  2. In Visual Studio, open the OneDrivePhotoBrowser.sln file and build it.

OneDrive Consumer configuration

Associate the sample app with the Windows Store

Before you can run the sample to use with OneDrive Consumer, you must associate the app with the Windows Store. To do this, right-click the OneDrivePhotoBrowser project and choose Store | Associate app with store. Associating the app with the Windows store is reqiured for authentication to succeed.

OneDrive for Business authentication does not require store association.

OneDrive for Business configuration

In order to authenticate using OneDrive for Business you'll need to enter your application details for the app. To do this, right-click the AccountSelection.xaml file and choose View Code.

Replace the following values at the top of the file with your application details:

    private readonly string oneDriveForBusinessClientId = "Insert your AAD client ID here";
    private readonly string oneDriveForBusinessReturnUrl = "Insert your AAD return URL here";

For more details on setting up an application to access OneDrive for Business please read the registration documentation for the API.

Run the sample

  1. With the sample open in Visual Studio, at the top, select Debug for Solution Configurations and x86 or x64 for Solution Platforms, and OneDrivePhotoBrowser for Startup project.
  2. Check that you are running the sample on the Local Machine.
  3. Press F5 or click Start to run the sample.

The OneDrive Photo Browser sample app will open the signed-in user's personal OneDrive, with only folders and images displayed. If the file is not an image, it will not show up in the OneDrive Photo Browser app. Select a folder to see all images in that folder. Select an image to see a larger display of the image, with scroll view.

API features

OneDrive sign-in

When the app loads, the user is presented with an account selection screen with two buttons: "Log in to MSA" and "Log in to AAD". If the user selects "Log in to MSA" the GetUniversalClient is called on the OneDriveClientExtensions object to get a OneDriveClient object. If the user selects "Log in to AAD" the GetActiveDirectoryClient is called on the BusinessClientExtensions object to get a OneDriveClient object.

Once a OneDriveClient object is returned, AuthenticateAsync completes the client authentication for the Windows Universal sample app. This will prompt the user to log in with the selected account type.

private async void InitializeClient(ClientType clientType, RoutedEventArgs e)
{
  if (((App)Application.Current).OneDriveClient == null)
  {
      var client = clientType == ClientType.Consumer
          ? OneDriveClientExtensions.GetUniversalClient(this.scopes) as OneDriveClient
          : BusinessClientExtensions.GetActiveDirectoryClient(
              oneDriveForBusinessAppId,
              oneDriveForBusinessReturnUrl) as OneDriveClient;

      try
      {
          await client.AuthenticateAsync();
          ...
      }
      catch (OneDriveException exception)
      {
          ....
          client.Dispose();
      }
  }
  ...
}

Get thumbnails for an image in OneDrive

In this example, thumbnails are returned for an item, if it is an image. GetAsync() is used to get the item's properties.

var childrenPage = await this.oneDriveClient.Drive.Items[id].Children.Request().Expand("thumbnails").GetAsync();
items = childrenPage == null
  ? new List<Item>()
  : childrenPage.CurrentPage.Where(item => item.Folder != null || item.Image != null);

More 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 opencode@microsoft.com with any additional questions or comments.