我使用下面的代码来读取azure中可用的所有文件:
private const string account = "Testaccount";
private const string key = "I1yMjhk1Pp10KBxU4mnuaxXnsupk3USn8B85TtSunXzO+WLZ+uYbFl/mCkD8Q7yqAA==";
private const string url = "http://Testaa.blob.core.windows.net/contractattachments/201503/20150302110215315197/20150331114910310626/Test%20-%20Copy%20-%20file.txt";
private const string containerName = "TestFiles";
private const string blobName = "File1";
static void Main(string[] args)
{
// get storage
StorageCredentialsAccountAndKey creds = new StorageCredentialsAccountAndKey(account, key);
CloudBlobClient blobStorage = new CloudBlobClient(url, creds);
//get blob container
CloudBlobContainer blobContainer = blobStorage.GetContainerReference(containerName);
BlobContainerPermissions permissions = new BlobContainerPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
blobContainer.SetPermissions(permissions);
//get blob data
CloudBlob cloudBlob = blobContainer.GetBlobReference(blobName);
//string text = cloudBlob.DownloadText();
// print text
// Console.WriteLine(text);
//List blobs and directories in this container
var blobs = blobContainer.ListBlobs();
List<string> listofblobs=new List<string>();
foreach (var blobItem in blobs)// Exception ----The requested URI does not represent any resource on the server.
{
blobItem.Container.GetPermissions();
}
foreach (var blobItem in blobs)
{
string BolbName = blobItem.Container.Name.ToString();
Console.WriteLine(blobItem.Uri);
}
}
&GT; 实际上我们有上面提到的存储帐户,该帐户中有容器。容器包含子文件夹和子文件夹包含..some文件.....所以我的要求是从可用的所有容器读取所有文件...所以我首先尝试从一个容器读取所有文件..但它给我例外如下 请求的URI不代表服务器上的任何资源。 请帮助我.....如果我遗失了任何东西,请告诉我......
答案 0 :(得分:1)
url
未指向Azure Blob服务帐户,即使该帐户已传递到CloudBlobClient's constructor。请考虑使用CloudStorageAccount,并使用CloudBlobClient实例化CreateCloudBlobClient。StorageCredentialsAccountAndKey
已在Azure Storage Client Library 2.0中删除,因此您使用的是旧版本。请考虑升级到最新版本以获得性能改进和错误修复。