C# 使用C在Azure中的存储容器之间复制Blob#
我编写了以下C#代码,用于在Azure中的存储容器之间复制blob。它不会抛出任何错误,但也不会给出输出C# 使用C在Azure中的存储容器之间复制Blob#,c#,azure,azure-storage-blobs,C#,Azure,Azure Storage Blobs,我编写了以下C#代码,用于在Azure中的存储容器之间复制blob。它不会抛出任何错误,但也不会给出输出 static void TransferBlob(string accountName, string accountKey, string containerName, string targetContainerName) { CloudStorageAccount storageAccount = new CloudStorageAccount(new Sto
static void TransferBlob(string accountName, string accountKey, string containerName, string targetContainerName)
{
CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer sourceContainer = cloudBlobClient.GetContainerReference(containerName);
CloudBlobContainer targetContainer = cloudBlobClient.GetContainerReference(targetContainerName);
CloudBlockBlob sourceBlob;
CloudBlockBlob targetBlob;
foreach (var blobItem in sourceContainer.ListBlobs())
{
sourceBlob = sourceContainer.GetBlockBlobReference(blobItem.Uri.ToString());
targetBlob = targetContainer.GetBlockBlobReference(blobItem.Uri.ToString());
targetBlob.StartCopy(sourceBlob);
}
}
您需要使用
useFlatBlobListing:true
和blob.Name
static void TransferBlob(string accountName, string accountKey, string sourceContainerName, string targetContainerName)
{
CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer sourceContainer = cloudBlobClient.GetContainerReference(sourceContainerName);
CloudBlobContainer targetContainer = cloudBlobClient.GetContainerReference(targetContainerName);
if (sourceContainer.Exists() && targetContainer.Exists())
{
foreach (IListBlobItem item in sourceContainer.ListBlobs(useFlatBlobListing: true))
{
var blob = item as CloudBlockBlob;
if (blob != null)
{
CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(blob.Name);
CloudBlockBlob targetBlob = targetContainer.GetBlockBlobReference(blob.Name);
targetBlob.StartCopy(sourceBlob);
}
}
}
}
您在Azure存储中使用哪个nuget软件包和版本?