Monday, 16 October 2017

Office URI Scheme

URI stands for Uniform Resource Identifier, used to uniquely identify a resource.

What is URI Scheme?
URI scheme tells how to interpret given URI.

MSOffice provides, office uri scheme, by using uri scheme commands, we can invoke office applications.

URI Scheme syntax
<scheme-name>:<command-name>"|"<command-argument-descriptor> "|"<command-argument>

Ex:
a. Below uri scheme opens the document presented in local file system.
Open run prompt and enter below url, if ms office is installed in your machine, it opens the document.
ms-word:ofv|u|file:///C:\Users\krishna\Documents\testDoc.docx

b. Below uri scheme opens the document presented in internet.
ms-word:ofv|u|http://sample.com/testDoc.docx

You can write a html file like below to open the file using office uri schema.

uriHandle.html
<!DOCTYPE html>
<html>
 <head>
  <title>Open Office URI</title>
  
  <script>
   function openURI() {
    var urlToLaunch = 'ms-word:ofv|u|file:///C:/Users/Krishna/Documents/testDoc.docx';
    if (navigator.msLaunchUri) {
     navigator.msLaunchUri(urlToLaunch);
    } else {
     var win = (window.parent) ? window.parent : window;
     win.location.assign(urlToLaunch);
    }
   }
  </script>

 </head>

 <body onLoad='openURI()'>
  <a href='ms-word:ofv|u|file:///C:\Users\Krishna\Documents\testDoc.docx'>ClickMe</a>
 </body>

</html>


Open above html file in browser. For example, I opened above file in chrome browser. Chrome browser prompts you with below kind of window, whether you want to open the file or not.

Click on the button ‘Open Word 2016’, it open the word document located in your machine.

Analyze the syntax of office uri scheme
<scheme-name>:<command-name>"|"<command-argument-descriptor> "|"<command-argument>

Token
Description
<scheme-name>
Scheme name specifies the office application to be invoked.

Ex:
         ms-word : Specifies office word application
         ms-powerpoint : Specifies the ppt application
:
Separate the uri scheme and commands
<command-name>
Specifies the action to be performed by the application.

Ex:
       ofe (Open for Edit): Open the document in edit mode
       ofv (Open for View): Open the document in view mode
       nft (New from template) : Create a file from given template
|
Separator
<command-argument-descriptor>
Add extra information about what the command argument is about.
|
Separator
<command-argument>
It vary depends on the command. For example, we can provide the uri (location of the document)

For ex: for the below uri scheme
ms-word:ofv|u|file:///C:/Users/krishna/Documents/testDoc.docx

<scheme-name> : ms-word
<command-name> : ofv
<command-argument-descriptor> : u

Compact form of Office Scheme
You can also use the compact form of office uri scheme.
<scheme-name>:<command-argument>

Ex
ms-word:file:///C:\Users\krishna\Documents\testDoc.docx

Above uri scheme open the document.

What are the uri schemes implemented as part of Microsoft Office applications?
When you install Microsoft Office, below uri schemes will be installed in your machine.

Below table summarizes the uri schemes comes as part of office installation.

URI Scheme
Description
ms-word
Office documents like .doc, .docx
ms-powerpoint
Power point (ppt) files
ms-excel
Excel sheet (xls, xlsx)
ms-visio
Visio files (.vsdx)
ms-access
Microsoft access files
ms-project
Microsoft project files
ms-publisher
Microsoft publisher application files (.pub)
ms-spd
Microsoft Sharepoint Designer files
ms-infopath
Info path forms

Is there any limitations in using uri scheme?
Yes, you should consider below limitations while using office uri scheme.

a.   File names must not contain following characters \ / : ? < > | " or *.
b.   The maximum command argument (path length) length is 256 characters, for xls files it is 216 characters.

Reference


You may like

No comments:

Post a Comment