In programming languages, a handler is something that has to be handled by writing explicit custom code.
Take, for example, event handlers in SharePoint for various events like when the Item is added, updated or deleted. Whenever these events occur, if we want to customize the default behavior of the system, we write a handler for that event in our custom logic.
The file handler can be displayed as a message when deleting an item or may be pre-checking the state of the system before a deletion or even just a simple logging when a particular item is deleted from the list.
Office 365 File Handlers
When we try to open any Microsoft files such as Word or PowerPoint, Office 365 knows how to deal with those files. For instance, it opens Word files in Word Online for previewing files and even editing them, so you can work with the file while inside the browser. But what if you want custom behavior for non-Microsoft file types? This is where Office 365 file handlers come into the picture.
Microsoft has provided a way of implementing file handlers in Office 365 to deal with non-Microsoft file types.
You can customize any existing file type or even entirely new file types which is proprietary of any organization. With file handlers we can customize the following behaviors for unknown file types:
- Customize the file Icon.
- We can get a file preview in the browser.
- Editing functionality for the file.
Why File Handlers?
Office 365 knows how to deal with Microsoft office file types. It shows the relevant icon for the file and will even read the file content for metadata properties as well as previewing the file when we look for properties. But for non-Microsoft Office file types or unknown file types, Office 365 will not automatically know how to read the file. That’s where file handlers come to the rescue.
What is a File Handler comprised of?
- File Handler Endpoint – This is our file handler application which provides the editing as well as the preview functionality for our file types.
- File Icon – This represents the image/icon of your file type to be shown in Office 365.
To create a file handler add-in for Office 365, we have to take the following steps:
- File Handler Template – There is a template readily available for creating file handlers. You can download it here
- App registration – Register your Office 365 app containing the file handler add-in within Windows Azure AD. You’ll have to set the below properties for creating the file handlers application:
- Client – The Office 365 client from which the file is opened or previewed.
- CultureName – The culture name of the current thread, used for localization.
- FileGet – The full URL of the REST endpoint your app calls to retrieve the file from Office 365.
- FilePut -The full URL of the REST endpoint your app calls to save the file back to Office 365. ResourceID – the URL of the Office 365 tenant used to get the access token from Azure AD.
- DocumentID – The document ID for a specific document; allows your application to open more than one document at the same time.
- Add-in Metadata in AAD Application Object – These specify the behavior of the file handler. You can add your properties in the add-in object. The manifest syntax will be something like below:
- Developing the code handler application – In the project we created using the file handler template, all the files will be automatically created with the placeholder methods.
You can find these methods in the FileHandlerController.cs file in the Controllers folder of the project solution.
For the Preview method, look for the following method declaration: public async Task Preview(). This method will be called when the file has to be previewed from the SharePoint library.
For the Open method, look for the following method declaration: public async Task Open(). This method will be called when the file has to be opened and to allow users to view or edit the file.
File handlers help Office 365 deal with unknown file types rather than lying in the repository as an unknown file type. They allow users to interact more dynamically with the files rather than simply downloading them to the system and then viewing them. File handlers also allow users to have different experiences with different type of files.
Are you using any specific Office 365 file handlers for your organization? Let us know in the comments.