Forum Discussion

KeffaKlumpen's avatar
KeffaKlumpen
Copper Contributor
Nov 02, 2023
Solved

Teams Tabs App - Finding the current team/site

I am currently developing a teams app that will be added to a few different teams.

We are using C# / .cshtml / Razor and the app consists of a few RazorComponents which performs different Graph operations on a SharePoint site.

Currently we are using a hard-coded siteId pointing to our Team-site used for testing, but now we need to find this siteId dynamically - to access the right site, depending on which team you opened the app through.

We found the MicrosoftTeams.GetTeamsContextAsync() which gives us a TeamsContext object - however the Teams field is null.

Is there a good way to do this that we just haven't found?
Or does anyone know of a not-so-good way that might work?
Or am I coming at this from the completely wrong direction?

  • We found the solution to why the TeamsContext object was not being assigned any data:
    In the manifest.json we had to add the "team" scope to our tab!

    Here we found the ChannelContext which contains a RelativeUrl we can extract the site name from!

2 Replies

  • KeffaKlumpen's avatar
    KeffaKlumpen
    Copper Contributor
    We found the solution to why the TeamsContext object was not being assigned any data:
    In the manifest.json we had to add the "team" scope to our tab!

    Here we found the ChannelContext which contains a RelativeUrl we can extract the site name from!

Resources