简体   繁体   English

从HttpPostedFileWrapper通过InputStream的Linq

[英]Linq over InputStream from HttpPostedFileWrapper

Is it possible to apply a Linq query from a HttpPostedFileWrapper? 是否可以从HttpPostedFileWrapper应用Linq查询?

My web app allows users to select a bunch of .csv files. 我的Web应用程序允许用户选择一堆.csv文件。 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? 但是,现在我有了HttpPostedFileWrapper对象的集合,我该怎么做?

edit 编辑

Or do I need to convert it to something and then read the file? 还是我需要将其转换为某种内容然后读取文件?

You may be able to loop over the file names instead of the input streams 您可能可以遍历文件名而不是输入流

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM