Back to column formats
Column formattingSharePoint Online

Share to teams

Adds an icon to share the current document in a Teams message

Share to teams formatting preview
Sample preview · View original animation

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "attributes": {
    "alt": "Share to Microsoft Teams",
    "iconName": "TeamsLogo",
    "class": "ms-fontColor-themePrimary",
    "href": "='https://teams.microsoft.com/share?href='+substring(@currentWeb,0,indexOf(@currentWeb,'sharepoint.com'))+'sharepoint.com'+[$FileRef]+'&web=1'",
    "target": "_blank"
  },
  "style": {
    "font-size": "26px",
    "text-decoration": "none",
    "visibility": "=if(((indexOf([$ContentTypeId],'0x0120')) == 0),'hidden', 'visible')"
  }
}

From the contributor

How to use this sample

Summary

This sample demonstrates how to add a "Share to Microsoft Teams" link into a document library. A new tab is opened once a user clicks the "Teams" icon, then the user will be asked in which team and channel to post the document.

screenshot of the sample

View requirements

The format can be applied to any column, although it is recommended to add it to a calculated column with a ="1" formula

Sample

Solution Author(s)
generic-share-to-teams.json Sven Sieverding

Version history

Version Date Comments
1.0 August 15, 2023 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.