Hello,
Welcome to our Microsoft Q&A platform!
To read data from the .csv file, try using the 'CsvHelper' nuget package. And for the xml file, try using the XmlSerializer class to get the data.
Check the link: https://stackoverflow.com/questions/9619324/how-to-read-xml-file-into-list
You could place the files in the shared project and set the Build Action to Embedded Resource. Then load the files to access the data:
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(CurrentClass)).Assembly;
Stream stream = assembly.GetManifestResourceStream("TestApplication.temp.csv");
using (var reader = new System.IO.StreamReader(stream))
{
if (reader != null)
{
using (var csvReader = new CsvReader(reader, CultureInfo.CurrentCulture))
{
while (csvReader.Read())
{
list.Add(new TestModel
{
costent = csvReader.GetField<string>(0),
...
});
}
}
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.