I am using this code to populate a list in C# with data from a Web Api that gets data from a csv file
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("http://localhost:12345/api/items");
var info = new List<SampleDataGroup>();
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var item = JsonConvert.DeserializeObject<dynamic>(content);
foreach (var data in item)
{
var infoSect = new SampleDataGroup
(
(string)data.Id.ToString(),
(string)data.Name,
(string)"",
(string)data.PhotoUrl,
(string)data.Description
);
info.Add(infoSect);
}
}
else
{
MessageDialog dlg = new MessageDialog("Error");
await dlg.ShowAsync();
}
I would like to assign a photo to (string)data.PhotoUrl,
depending on its Name
.
For example: If the Name
is "Car", I would like it to be assigned the PhotoUrl
"Assets/Images/car.jpg". If an item in the lists Name
is "Boat", assign it's PhotoUrl
to "Assets/Images/boat.jpg".
The Images are not included of the CSV file that the web api feeds on.
There will be more than one item in the list with the same Name
, but all with the same Name
will share the same assigned image.
How do I do this?