Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C在Azure中的存储容器之间复制Blob#_C#_Azure_Azure Storage Blobs - Fatal编程技术网

C# 使用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

我编写了以下C#代码,用于在Azure中的存储容器之间复制blob。它不会抛出任何错误,但也不会给出输出

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软件包和版本?