{"id":20054317,"url":"https://github.com/onedrive/onedrive-sample-photobrowser-uwp","last_synced_at":"2025-05-05T13:31:09.571Z","repository":{"id":83458887,"uuid":"62753588","full_name":"OneDrive/onedrive-sample-photobrowser-uwp","owner":"OneDrive","description":null,"archived":false,"fork":false,"pushed_at":"2019-10-25T21:17:42.000Z","size":71,"stargazers_count":10,"open_issues_count":2,"forks_count":13,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-08T23:23:45.309Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OneDrive.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-06T21:11:22.000Z","updated_at":"2024-05-25T10:52:07.000Z","dependencies_parsed_at":"2023-04-17T06:16:40.899Z","dependency_job_id":null,"html_url":"https://github.com/OneDrive/onedrive-sample-photobrowser-uwp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneDrive%2Fonedrive-sample-photobrowser-uwp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneDrive%2Fonedrive-sample-photobrowser-uwp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneDrive%2Fonedrive-sample-photobrowser-uwp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OneDrive%2Fonedrive-sample-photobrowser-uwp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OneDrive","download_url":"https://codeload.github.com/OneDrive/onedrive-sample-photobrowser-uwp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252506385,"owners_count":21759040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T12:39:47.393Z","updated_at":"2025-05-05T13:31:09.558Z","avatar_url":"https://github.com/OneDrive.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\r\npage_type: sample\r\nproducts:\r\n- office-onedrive\r\nlanguages:\r\n- csharp\r\nextensions:\r\n  contentType: samples\r\n  createdDate: 7/6/2016 2:11:22 PM\r\n---\r\n# OneDrive Photo Browser sample\n\nThe OneDrive Photo Browser sample is a Windows Universal app that uses the OneDrive SDK for C#/.NET. \nThe sample app displays only items that are images from a user's OneDrive. Note that this sample does not work with OneDrive for Business.\n\n## Set up\n\n### Prerequisites\n\nTo run the sample, you will need: \n\n* 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](https://msdn.microsoft.com/en-us/library/windows/apps/dn609832.aspx).\n* A Microsoft account and/or Azure Active Directory account with access to OneDrive for Business\n* Knowledge of Windows Universal app development\n\n### Download the sample\n\n1. Download the sample from [GitHub](https://github.com/OneDrive/onedrive-sample-photobrowser-uwp) by choosing **Clone in Desktop** or **Download Zip**. \n2. In Visual Studio, open the **OneDrivePhotoBrowser.sln** file and build it.\n\n## OneDrive Consumer configuration\n\n### Associate the sample app with the Windows Store\n\nBefore 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.\n\nOneDrive for Business authentication does not require store association.\n\n## OneDrive for Business configuration\n\nIn 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**.\n\nReplace the following values at the top of the file with your application details:\n\n```csharp\n    private readonly string oneDriveForBusinessClientId = \"Insert your AAD client ID here\";\n    private readonly string oneDriveForBusinessReturnUrl = \"Insert your AAD return URL here\";\n```\n\nFor more details on setting up an application to access OneDrive for Business please read the [registration documentation](https://dev.onedrive.com/app-registration.htm#register-your-app-for-onedrive-for-business) for the API.\n\n## Run the sample\n\n1. 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. \n2. Check that you are running the sample on the **Local Machine**.\n3. Press **F5** or click **Start** to run the sample.\n\nThe 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.\n\n## API features\n\n### OneDrive sign-in\n\nWhen 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.\n\nOnce 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.\n\n```csharp\nprivate async void InitializeClient(ClientType clientType, RoutedEventArgs e)\n{\n  if (((App)Application.Current).OneDriveClient == null)\n  {\n      var client = clientType == ClientType.Consumer\n          ? OneDriveClientExtensions.GetUniversalClient(this.scopes) as OneDriveClient\n          : BusinessClientExtensions.GetActiveDirectoryClient(\n              oneDriveForBusinessAppId,\n              oneDriveForBusinessReturnUrl) as OneDriveClient;\n              \n      try\n      {\n          await client.AuthenticateAsync();\n          ...\n      }\n      catch (OneDriveException exception)\n      {\n          ....\n          client.Dispose();\n      }\n  }\n  ...\n}\n```\n\n### Get thumbnails for an image in OneDrive\n\nIn this example, thumbnails are returned for an item, if it is an image. `GetAsync()` is used to get the item's properties.\n\n```csharp\nvar childrenPage = await this.oneDriveClient.Drive.Items[id].Children.Request().Expand(\"thumbnails\").GetAsync();\nitems = childrenPage == null\n  ? new List\u003cItem\u003e()\n  : childrenPage.CurrentPage.Where(item =\u003e item.Folder != null || item.Image != null);\n```\n\n## More resources\n\n* [OneDrive SDK for .NET](https://github.com/OneDrive/onedrive-sdk-csharp) documentation\n* [OneDrive API](https://dev.onedrive.com/) - Official documentation for the OneDrive API\n* [OneDriveApiBrowser](https://github.com/OneDrive/onedrive-sample-apibrowser-dotnet) - A Windows Forms sample app using OneDrive SDK for CSharp \n* [Windows Universal apps](https://msdn.microsoft.com/en-us/library/windows/apps/dn726767.aspx) - More information about Windows Universal apps\n\n## License\n\n[License](LICENSE.txt)\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonedrive%2Fonedrive-sample-photobrowser-uwp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonedrive%2Fonedrive-sample-photobrowser-uwp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonedrive%2Fonedrive-sample-photobrowser-uwp/lists"}