我想编写一个程序来从 azure 文件存储中获取文件,但问题是未定义目录深度并且isFile
文件的属性始终返回 false。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.Azure; // Namespace for Azure Configuration Manager
using Microsoft.WindowsAzure.Storage; // Namespace for Storage Client Library
using Microsoft.WindowsAzure.Storage.Blob; // Namespace for Blob storage
using Microsoft.WindowsAzure.Storage.File; // Namespace for File storage
namespace AzureStorage
{
class Program
{
static void Main(string[] args)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
//CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Create a CloudFileClient object for credentialed access to File storage.
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
// Get a reference to the file share we created previously.
CloudFileShare share = fileClient.GetShareReference("my-FileShare");
// Ensure that the share exists.
if (share.Exists())
{
// Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
// Get a reference to the directory we created previously.
CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("FILES");
// Ensure that the directory exists.
if (sampleDir.Exists())
{
var directoryLists = sampleDir.ListFilesAndDirectories();
//sampleDir.ge
foreach (var yearDirTemp in directoryLists)
{
var yearDir = sampleDir.GetDirectoryReference(
Path.GetFileNameWithoutExtension(yearDirTemp.Uri.LocalPath)
);
foreach (var monthDirTemp in yearDir.ListFilesAndDirectories())
{
var monthDir = yearDir.GetDirectoryReference(
Path.GetFileNameWithoutExtension(monthDirTemp.Uri.LocalPath)
);
foreach (var patientDirTemp in monthDir.ListFilesAndDirectories())
{
var patientDir = monthDir.GetDirectoryReference(
Path.GetFileNameWithoutExtension(patientDirTemp.Uri.LocalPath)
);
foreach (var patientDataTemp in patientDir.ListFilesAndDirectories())
{
var patientData = patientDir.GetDirectoryReference(
Path.GetFileNameWithoutExtension(patientDataTemp.Uri.LocalPath)
);
var fileList = patientData.ListFilesAndDirectories();
foreach(var fileTemp in fileList)
{
// Here fileTemp could be file
// or directory containing more child directories
var file1 = patientData.GetFileReference(Path.GetFileName(fileTemp.Uri.LocalPath));
file1.FetchAttributes();
byte[] arrTarget = new byte[file1.Properties.Length];
file1.DownloadToByteArray(arrTarget, 0);
}
}
}
}
}
}
}
}
}
}