[英]How to read a CSV file from Azure File share into a memory stream using C#?
I'm working on a requirement where I need to read CSV files from Azure File Share location(Not Azure blob) using C# console application. I'm working on a requirement where I need to read CSV files from Azure File Share location(Not Azure blob) using C# console application. I've got to a point where I'm able to read the file as seen in the below code.
我已经到了可以读取文件的程度,如下面的代码所示。
But how can I get the file content into a memory stream?但是如何将文件内容放入 memory stream 中?
// List all files/directories under the root directory
IEnumerable<IListFileItem> fileList = fileShare.GetRootDirectoryReference()
.ListFilesAndDirectories();
if (fileList != null)
{
foreach (IListFileItem listItem in fileList)
{
if (listItem.GetType() == typeof(CloudFile))
{
Console.WriteLine("Retrieved File: " + listItem.Uri.Segments.Last());
WriteToLog("Retrieved File: " + listItem.Uri.Segments.Last());
_filename = listItem.Uri.Segments.Last();//Gets the CSV file name
}
}
Thanks谢谢
I was able to download the file to stream using the below code.我能够使用以下代码将文件下载到 stream。 Hope this is helpful to someone trying to achieve this with a CSV input file.
希望这对尝试使用 CSV 输入文件实现此目的的人有所帮助。
CloudFile file = fileShare.GetRootDirectoryReference().GetFileReference(_blobfilename); CloudFile 文件 = fileShare.GetRootDirectoryReference().GetFileReference(_blobfilename);
long? offset = Convert.ToInt64(file.Properties.Length * 0);
long? length = Convert.ToInt64(file.Properties.Length * -100);
file.DownloadRangeToStream(ms, null, null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.