我必须对csv文件的上传进行一定的限制。
包装器C#代码。
using (var stream = File.OpenRead("C:\~~~\~~~\~~~\SampleFile.csv"))
{
//CSV Header removal snippet - which gives me a new stream containing data without headers.
~
~
~
~
//All my stream handling code of chunking stream into 100mb and then uploading each chunk to azure storage (which is not part of this question)
}
现在我已经知道了--我可以使用像--这样的库简单地删除csv文件的头。CSVHelper
(将数据写入CSV时,如何排除头文件?)
使用上面的方法,我可以创建一个文件的无头拷贝,并将新文件以FileStream的形式读回来--但问题是,我正在处理大文件,仅仅为了删除头而复制一个文件将是一项耗费空间的工作。
所以第一次--我在StackOverflow上提出一个问题--寻找解决上述问题的好办法。我希望我能够解释清楚这个问题。
这应该可以搜索到第一行的末尾。
using (var stream = File.OpenRead("~~filepath~~"))
using (var reader = new StreamReader(stream))
{
string line = null;
if ((line = reader.ReadLine()) != null)
{
stream.Position = line.Length + 2;
// The 2 is for NewLine(\r\n)
}
//All my stream handling code of chunking stream into 100mb and then uploading each chunk to azure storage (which is not part of this question)
}