问题描述
我正在处理一个需要使用 C# 控制台应用程序从 Azure 文件共享位置(不是 Azure blob)读取 CSV 文件的要求。我已经达到了能够读取文件的程度,如下面的代码所示。
// 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
}
}
谢谢
解决方法
我能够使用以下代码下载文件以进行流式传输。希望这对尝试使用 CSV 输入文件实现此目的的人有所帮助。
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);