如何在azure文件存储上上传和下载文件。 此外,我需要获取文件列表并显示到数据网格视图。
答案 0 :(得分:-2)
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(YOUR_CONNECTION_STRING);
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
// Locate the directory. ( Sharename\Root\Dir1\Dir2 )
CloudFileDirectory cfDir = fileClient.GetShareReference("app-updates").GetRootDirectoryReference().GetDirectoryReference("test").GetDirectoryReference("v1");
// Get File Reference
CloudFile cloudFile = cfDir.GetFileReference("testFileOnCloud.txt");
// Upload
cloudFile.UploadFromFileAsync(@"D:\toupload.txt", FileMode.Open);
// Download
cloudFile.DownloadToFileAsync(@"D:\downloaded.txt", FileMode.OpenOrCreate);
// Get file List
List<CloudFile> lstFiles = cfDir.ListFilesAndDirectories().OfType<CloudFile>().ToList();
dataGridView1.DataSource = lstFiles.Select(x => new { Name = x.Name, Size = x.Properties.Length}).ToList();