How can we help you today?

How to Open Microsoft Office Files Directly in Your Office Client Application (Word, Excel or Powerpoint) from ShortPoint

You have a File list (or any other) ShortPoint connected to files in your document library and you want to launch Microsoft Office client application directly when clicking on the files (type: Word, Excel or PowerPoint):




To use the above ShortPoint with the given design and code, please copy the ShortPoint code below to your page:



[files-list color="highlight"][file-list-item shortpoint_connection="%7B%22id%22%3A%22dynamic_rest%22%2C%22data%22%3A%7B%22url%22%3A%22https%3A%2F%2Fshortpoint1.sharepoint.com%2Fsites%2FNewModern%2F_api%2Fweb%2Flists%2Fgetbytitle('Templates')%2Fitems%3F$select%3DFileLeafRef%2CEncodedAbsUrl%2CModified%2CCreated%2CEditor%2FTitle%2CFile_x0020_Type%26$expand%3DEditor%26$orderby%3DFileLeafRef%2520asc%22%2C%22itemsLimit%22%3A0%2C%22mapResults%22%3A%22var%20files%20%3D%20data.d.results%3B%5Cnvar%20filesWithDirectUrl%20%3D%20files.map(function(file)%20%7B%5Cnif(file.File_x0020_Type%20%3D%3D%20%5C%22docx%5C%22)%5Cn%7B%5Cn%5Ctfile.DirectUrl%20%3D%20%5C%22ms-word%3Anft%7Cu%7C%5C%22%20%2B%20file.EncodedAbsUrl%3B%5Cn%7D%5Cnelse%20if(file.File_x0020_Type%20%3D%3D%20%5C%22xlsx%5C%22)%5Cn%7B%5Cn%5Ctfile.DirectUrl%20%3D%20%5C%22ms-excel%3Anft%7Cu%7C%5C%22%20%2B%20file.EncodedAbsUrl%3B%5Cn%7D%5Cnelse%20if(file.File_x0020_Type%20%3D%3D%20%5C%22pptx%5C%22)%5Cn%7B%5Cn%5Ctfile.DirectUrl%20%3D%20%5C%22ms-powerpoint%3Anft%7Cu%7C%5C%22%20%2B%20file.EncodedAbsUrl%3B%5Cn%7D%5Cnreturn%20file%3B%5Cn%7D)%3B%5Cnreturn%20filesWithDirectUrl%3B%5Cn%22%7D%2C%22caching%22%3Anull%7D" title="%23FileLeafRef" subtitle="created%20by%20%23Editor__Title" file-type="%23File_x0020_Type" link="%23DirectUrl" /][/files-list]



Prerequisites


  1. You need to be logged in at Microsoft Office with the same account as you are logged in to your browser


  2. You need to have Microsoft Office Installed at users' machine



Step 1: Add File Lists ShortPoint to the page


Add any element to the page In this example, I am going to add File Lists ShortPoint but this solution is not restricted to it.



Go to Connect and Select Rest API connection type;




Step 2: Connect to files and make it open with Microsoft Office client application


https://<Tenancy Name>.sharepoint.com/_api/web/lists/getbytitle('<Document Library Name>')/items?$select=FileLeafRef,EncodedAbsUrl,Modified,Created,Editor/Title,File_x0020_Type&$expand=Editor&$orderby=FileLeafRef%20asc


<Tenancy Name>: This should be URL to your web (for example https://shortpoint.sharepoint.com/sites/demo)

<Document Library Name>This should be the title (Name) of your document library


To have more options about sorting the file list, you can follow How to show both Files and Folders of the Document Library in your ShortPoint element article's Step 2.


Example URL: https://shortpoint.sharepoint.com/_api/web/lists/getbytitle('Templates')/items?$select=FileLeafRef,EncodedAbsUrl,Modified,Created,Editor/Title,File_x0020_Type&$expand=Editor&$orderby=FileLeafRef%20asc



Now we need to make a URL which will make files open directly in Microsoft Office Client application. To do that, check Enable Advanced Settings and provide following JavaScript code in Map Results:


var files = data.d.results;
var filesWithDirectUrl = files.map(function(file) {
if(file.File_x0020_Type == "docx")
{
file.DirectUrl = "ms-word:nft|u|" + file.EncodedAbsUrl;
}
else if(file.File_x0020_Type == "xlsx")
{
file.DirectUrl = "ms-excel:nft|u|" + file.EncodedAbsUrl;
}
else if(file.File_x0020_Type == "pptx")
{
file.DirectUrl = "ms-powerpoint:nft|u|" + file.EncodedAbsUrl;
}
else
{
file.DirectUrl = file.EncodedAbsUrl;
}
return file;
});
return filesWithDirectUrl;



Click Connect. 


Here are the sample mappings in Item tab, however you can do mappings the way you want:



That's it!


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

World's best intranet sites are designed using ShortPoint

Get started today! Learn more
See all 31 topics

Start a trial

Ignite your vision. Install ShortPoint directly on your site, or play in sandbox mode. No credit card required.

Get started today

World’s best intranet sites are designed using ShortPoint

Thousands of companies using ShortPoint everyday to design, brand and build award winning intranet sites.

Get started Learn more