I have created a bot using c#.net. I am fetching data from the SharePoint list and it will fetch a number of rows. The number of rows is dynamic. I want to add data in a Table format when the bot will answer in Teams. I want to use adaptive cards for showing data in a table format, but how do I bind that data in an adaptive card as the number of rows will change according to question asked to bot? How can I bind data to cad dynamically in c#.net bot code?
Asked
Active
Viewed 1,719 times
0
-
Are you trying to use [Adaptive Card templating](https://learn.microsoft.com/en-us/adaptive-cards/templating/)? – Kyle Delaney Jan 28 '20 at 19:10
-
Are you still working on this? – Kyle Delaney Feb 03 '20 at 19:55
1 Answers
0
This is no problem at all, you can simply build up the adaptive cards server-side (i.e. in your bot) with the amount of rows. It's possible to either construct the JSON for the adaptive card as a string (using stringbuilder) or, as you're using C#, you can using the strongly typed AdaptiveCards nuget package and do it all in C#, something like:
var items = new System.Collections.Generic.List<AdaptiveElement>();
for (int i = 0; i < whatever.count; i++)
{
items.Add(new AdaptiveTextBlock()
{
Text = $"Item {i}",
});
}
card.Body.Add(
new AdaptiveContainer()
{
Items = items
}
);
I discuss this more in this answer: How to convert custom json to adaptive card json format

Hilton Giesenow
- 9,809
- 2
- 10
- 24
-
my requirement is that retrieving Sharepoint column values and that data should be bind with a card? how can I bind that data with template JSON of card? – Priya Jan 29 '20 at 06:04
-
Are you using Templating? If so, I can't help as I've not played with it, certainly not in terms of looping like this. It's in preview anyway though, so you could create your card in C# like above for now, and possibly change it to Templating later (or just leave as is) – Hilton Giesenow Jan 29 '20 at 06:55
-
I followed this link https://blog.botframework.com/2017/06/07/adaptive-card-dotnet/ to create an adaptive card, how can I create a card in c#, can u show some code – Priya Jan 29 '20 at 07:09
-
there's an example in that link, it's just much further down the page - search for "private static AdaptiveCard GetCard(string place)". It definitely shows how to do it, but there's lots of calling into sub methods - if you card is simple you can do it just in a one slightly longer method. – Hilton Giesenow Jan 29 '20 at 07:38
-
Can you add some info about the file structure? I'm also trying to do this, but I don't know how the file structure works and how a card can reference dynamic data in a project. All the samples I've seen show code but nothing about file structure – SendETHToThisAddress Jul 08 '21 at 04:37