Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.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# 如果目标中存在blob,如何覆盖blob_C#_Azure_Copy_Azure Storage_Azure Storage Blobs - Fatal编程技术网

C# 如果目标中存在blob,如何覆盖blob

C# 如果目标中存在blob,如何覆盖blob,c#,azure,copy,azure-storage,azure-storage-blobs,C#,Azure,Copy,Azure Storage,Azure Storage Blobs,我使用TransferManager将blob从一个容器复制到另一个容器 CloudStorageAccount sourceStorageAccount = CloudStorageAccount.Parse(@"source storage account connection string"); CloudStorageAccount destStorageAccount = CloudStorageAccount.Parse(@"destination storage account c

我使用
TransferManager
将blob从一个容器复制到另一个容器

CloudStorageAccount sourceStorageAccount = CloudStorageAccount.Parse(@"source storage account connection string");
CloudStorageAccount destStorageAccount = CloudStorageAccount.Parse(@"destination storage account connection string");

CloudBlobClient sourceBlobClient = sourceStorageAccount.CreateCloudBlobClient();
CloudBlobClient destBlobClient = destStorageAccount.CreateCloudBlobClient();
var sourceContainer = sourceBlobClient.GetContainerReference("sourceContainer");
var destContainer = destBlobClient.GetContainerReference("destContainer");

CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference("copy.txt");
CloudBlockBlob targetBlob = destContainer.GetBlockBlobReference("copy.txt");

TransferManager.CopyAsync(sourceBlob, targetBlob, true).Wait();
但当文件存在于目标中时,它会抛出错误声明

“跳过文件 \"\" 因为目标 \"\" 已存在。“}系统。异常 {Microsoft.WindowsAzure.Storage.DataMovement.TransferSkippedException


如果目标中存在文件,是否有覆盖该文件的选项?

您可能从中收到异常

我想你能做的是如下所示

TransferContext transferContext = new SingleTransferContext();
transferContext.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite;
TransferManager.CopyAsync(sourceBlob, targetBlob, true,null,transferContext).Wait();

我不太清楚,但我在github上发现了一些测试用例

@Curiousdev我不想这样,我更具体地说是在
Azure数据移动
中寻找选项。是的,我刚刚读到它,我错了,因为你使用TransferManager从一个容器复制到另一个容器……你试过了吗?工作得很好!