0

Is it possible to apply a Linq query from a HttpPostedFileWrapper?

My web app allows users to select a bunch of .csv files. I now need to open those files and import them.

My previous code, which uses paths and file names looks like;

            importedList = (from csvLine in File.ReadAllLines(fileName)
                            let x = csvLine.Split(',')
                            select new ImportedXDock
                            {
                                StoreNumber = int.Parse(x[0]),
                                DCNumber = int.Parse(x[1]),
                                DeliveryDay = x[2],
                                Activity = x[3],
                                ActivityDay = x[4],
                                Time = TimeSpan.Parse(x[5])

                            }).ToList();

However, now that i have a collection of HttpPostedFileWrapper objects how would I do the same?

edit

Or do I need to convert it to something and then read the file?

4

1 回答 1

1

您可以循环遍历文件名而不是输入流

foreach (var fileName in wrapper.Select(w => w.FileName))
{
    yield return (from csvLine in File.ReadAllLines(fileName)
                    let x = csvLine.Split(',')
                    select new ImportedXDock
                    {
                        StoreNumber = int.Parse(x[0]),
                        DCNumber = int.Parse(x[1]),
                        DeliveryDay = x[2],
                        Activity = x[3],
                        ActivityDay = x[4],
                        Time = TimeSpan.Parse(x[5])

                    }).ToList();
}
于 2013-04-30T00:36:01.870 回答