| page_type | sample | ||||
|---|---|---|---|---|---|
| description | This sample demos a bot with capability to upload files to SharePoint site and same files can be viewed in Teams file viewer. | ||||
| products |
|
||||
| languages |
|
||||
| extensions |
|
||||
| urlFragment | officedev-microsoft-teams-samples-bot-sharepoint-file-viewer-csharp |
Using this C# sample, a bot with capability to upload files to SharePoint site and same files can be viewed in Teams file viewer
-
.NET Core SDK version 6.0
# determine dotnet version dotnet --version -
Publicly addressable https url or tunnel such as ngrok or Tunnel Relay
Refer to Bot SSO Setup document.
- Run ngrok - point to port 3978
# ngrok http -host-header=rewrite 3978-
SharePoint site configuration
- Login to sharepoint
- Click on
Create siteand selectTeam site
- Enter site name and description of site.
-
From site address eg: 'https://m365x357260.sharepoint.com/sites/SharePointTestSite'
m365x357260.sharepoint.com- value is sharepoint tenant name.- Click on next. (optional step)Add aditional owner and member.
- Click on Finish.
1 Clone the repository
```bash
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
```
2 In a terminal, navigate to samples/bot-sharepoint-file-viewer/csharp/BotWithSharePointFileViewer
3 If you are using Visual Studio
- Launch Visual Studio
- File -> Open -> Project/Solution
- Navigate to
samples/bot-sharepoint-file-viewer/csharpfolder - Select
BotWithSharePointFileViewer.csprojorBotWithSharePointFileViewer.slnfile
4 Update the appsettings.json configuration for the bot to use the MicrosoftAppId, MicrosoftAppPassword, MicrosoftAppTenantId and ConnectionName generated in Step 1 (Setup for Bot SSO). (Note the App Password is referred to as the "client secret" in the azure portal and you can always create a new client secret anytime.)
ApplicationBaseUrlwill be your app's base url. For eghttps://xxxx.ngrok.io.SharePointTenantNamewill be the tenant name generated in step 3.2.SharePointSiteNamewill be the site name created in step 3.
5 Run your bot, either from Visual Studio with F5 or using dotnet run in the appropriate folder.
- This step is specific to Teams.
- Edit the
manifest.jsoncontained in theAppManifestfolder to replace your Microsoft App Id (that was created when you registered your bot earlier) everywhere you see the place holder string<<Microsoft-App-Id>>(depending on the scenario the Microsoft App Id may occur multiple times in themanifest.json) - Edit the
manifest.jsonforvalidDomainswith base Url domain. E.g. if you are using ngrok it would behttps://1234.ngrok.iothen your domain-name will be1234.ngrok.io. - Zip up the contents of the
AppManifestfolder to create amanifest.zip(Make sure that zip file does not contains any subfolder otherwise you will get error while uploading your .zip package) - Upload the
manifest.zipto Teams (In Teams Apps/Manage your apps click "Upload an app". Browse to and Open the .zip file. At the next dialog, click the Add button.) - Add the app to personal/team/groupChat scope (Supported scopes)
- Edit the
You can interact with this bot in Teams by sending it a message, or selecting a command from the command list. The bot will respond to the following strings.
-
The
viewfilecommand will list all the files that are uploaded to sharepoint site.
-
The
uploadfilecommand will return a card, which will open a task module from where new files can be uploaded to sharepoint.

To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.



