Back
Dev

Office 365 APIs Starter Project for Windows

Share on Facebook Share on Twitter Share on Linkedin Share via OneNote Share via Email Print

We’re building a set of starter projects that are intended to help you become familiar with the different Office 365 client libraries on the platforms you care about. In each project, we’ll show you how to use the client libraries to integrate your users’ Office 365 data into your app.

Using the Office 365 client libraries can simplify your life greatly as you code against the Office 365 APIs from your app. Here are just a few  examples:

  • Use the client libraries’ authentication business logic for getting the client access token. This means you don’t have to implement the authentication, authorization, and consent workflow that’s required for OAuth.
  • The client libraries remove the requirement to implement JSON serialization/deserialization in to/from objects; they have parity with the service metadata description; they manage the client access token; and they can make the object model easier to use.
  • Using the client libraries, you can leverage the Office 365 services to access your users’ calendar, mail, contacts, files, and sites.
  • Use the client libraries’ segmentation of feature access and user permissions. This means you can limit the access to specific features (for example, give access to contacts, but not email), as well as limit particular actions (for example, give read-only access).

We just shipped our first starter project to GitHub, Office 365 APIs Starter Project for Windows, and we can’t wait to hear what you think. The sample demonstrates how you can use the Office 365 API client libraries to integrate your users’ Office 365 data into your Windows Store app. Download it today!

Over the coming months we hope to also deliver starter projects for ASP.NET MVC, Android using Eclipse, Android using Xamarin, Cordova and many more. Check back here for updates to this project and announcements of new starter projects.

The Office 365 APIs Starter Project for Windows can help you:

  • Learn how the client libraries provided by Office 365 API Tools are used to make calls that target data stored in Office 365.
  • Build a Windows Store app that integrates your user’s Office 365 data.
  • Learn how to access calendar, files, folders and user information from Office 365.

Let’s take a look at the code in the Office 365 APIs Starter Project for Windows sample. If you haven’t already, we suggest that you download or clone this sample to your desktop and install it. The readme file contains the instructions for setting up the sample so that you can run it against a demo tenant.

Authenticate and get user information

When the sample is launched, you’ll see the screen shown below. Among other things, this page lists the Office 365 services with which you can interact.

MainPage.xaml is where you connect to Office 365

MainPage.xaml is where you connect to Office 365.

From here, you can connect to your Office 365 tenant. The Sign In button triggers a webpage that asks for your consent to allow this application to connect to the services requested by this application. This will get the access token that your application will use to connect to the service. The code we use to connect to the Office 365 services is found in the AuthenticationHelper.cs file. After the user has consented to let the application connect to the Office 365 services, we get the signed-in user’s information from Azure Active Directory (note that the Thumbnail feature is not available in this release). This work is carried out in the UserOperations.cs file.

Calendar API: Create, read, update and delete calendar events from your Office 365 calendar

Select the Calendar button on the start page to launch the Office 365 Calendar API example page, to work with your calendar events stored in Office 365. This is shown in the image below.

Calendar.xaml is where you access Office 365 events

Calendar.xaml is where you access Office 365 events.

This page uses the CalendarViewModel.cs and EventViewModel.cs files to access calendar information stored in your calendar. Look at CalendarOperations.cs to learn how you can:

  • Get the list of calendar events
  • Create a new event
  • Update an existing event
  • Remove an event from your calendar.

My Files API: Create, read, update and delete your files stored in SharePoint

Select the Files button from the start page to launch the Office 365 Files API example page, to access your files and folders in Office 365. You can see this in the image below.

MyFiles.xaml is where you access Office 365 files and folders

MyFiles.xaml is where you access Office 365 files and folders.

This page uses the FilesViewModel.cs and FileSystemItemViewModel.cs to access files and folder information stored in SharePoint. Look at FileOperations.cs to learn how to make calls to:

  • Get a list of all the files and folders in your default documents directory and sub-directory.
  • Create a simple text file.
  • Upload a file to SharePoint.
  • Delete a file or folder.
  • Read the contents of text file.
  • Update the contents of a text file.
  • Download a file. The code to then open the file is located in FilesViewModel.cs.

Questions and comments

Stay tuned to this blog for more updates and information about Office 365 development. We’d love to get your feedback and suggestions on this solution!

You can send your questions and suggestions to us:

  • Here, in the comments section on this blog post. Scroll down to the Join the conversation section.
  • In the Issues section of our GitHub repository for this project.
  • In StackOverflow. Make sure your questions/comments are tagged with [Office365] and [API].

Additional resources

Office 365 APIs Starter Project for Windows, repository on GitHub

Office 365 APIs Preview documentation

Files REST API in Office 365 APIs Preview

Calendar REST API in Office 365 APIs Preview

Office 365 API tool for Visual Studio 2013–update 3

Office Dev Center

 

 

Top

Join the conversation

5 comments
  1. Great sample! Much better than the one referenced in the preview blog.

    Two points of interest:
    -I’m receiving a Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)) on build. But after I gently ignore the message, the app runs anyway.
    -The app returns a message saying it cannot update my Calendar, but after checking my Outlook, my calenar apparently has been changed by the API anyway.

    • Thank you for your comments, Martin.
      Unfortunately I can’t reproduce the error you mention. However, I have a couple questions that might shed some light.
      – What is your target platform? (Look into the project properties -> Build tab -> Platform target)
      Just for reference. I’m using “Any CPU”
      – What is your OS? Windows 8, 8.1?
      – Does the error tell you what class or resource is not registered?

      • Hi Ricalo,

        Any CPU, windows 8.1 and not class or resource is mentioned. Quite clear huh!? Anyway, I’ll just ignore it and hope it doesn’t pop up in one of my own projects.

  2. While I was able to run the sample, and can see some great uses, there is part I don’t understand.

    If one of the first things I must do is to add the Office 365 Service using my info, then doesn’t mean that the app will only run on that tenant? When I tried to run it with the log on for another of my Office 365 accounts it did not work.

    So this makes me ask how can this be a Windows Store App when it will only work for my Office 365 account?

    Did I miss something, that would enable it to set up for other users against their Office 365?

    • Hi Robert,

      Thanks for trying out the sample. I’d like to answer each of your questions below. Please remember, the Office 365 APIs and client library are still in preview, so there are some known issues.

      Q: If one of the first things I must do is to add the Office 365 Service using my info, then doesn’t mean that the app will only run on that tenant?

      A: We do support multiple tenants. You can make your app available to your own tenant as well as other Office 365 tenants. When you add Office 365 connected services to a Windows Store app, it is configured by default to support multiple tenants. You can read more info here: http://chakkaradeep.com/index.php/making-your-office-365-app-available-to-multiple-organizations/

      Q: When I tried to run it with the log on for another of my Office 365 accounts it did not work. So this makes me ask how can this be a Windows Store App when it will only work for my Office 365 account?

      A: Unfortunately, you are hitting a known issue with the client library, which we noted in the sample’s readme file. You currently can’t switch users, i.e., sign in as user A, sign out and then sign in as user B. The only thing you can do right now is to uninstall the app, run it again and sign in as another user. For example, when I run the sample from my development environment, I log in as user A, then I stop debugging, uninstall the app from the machine, re-run the sample and log in as another user. I’ve also packaged the app and side-loaded it onto multiple machines. On each machine I can sign into whatever tenant, and as whatever user I want. The limitation today is that I can’t switch user on any of these installs. I hope that makes sense. The product team is aware of this issue and is working on it.

      Q: Did I miss something, that would enable it to set up for other users against their Office 365?
      A: You’ve done nothing wrong, you’re just witnessing a limitation that exists right now in this preview release. As I said, it is a known issue related to the preview bits and not a specific problem with this sample.

      Thanks,

      Andrew

Comments are closed.