Reputation: 5851
I am trying to copy the blob from one directory and past into other directory and the delete the blob from source. I already tried the below code but not copy and past into another folder is done but delete operation works.
var cred = new StorageCredentials("storageName", "Key");
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("containerName");
CloudBlockBlob sourceBlob = container.GetBlockBlobReference("folder/test.jpg");
//this doesn't work
sourceBlob.StartCopyAsync(new Uri("destination url"));
//this works
sourceBlob.DeleteAsync();
Upvotes: 6
Views: 7259
Reputation: 6467
You need to await
as Igor mentioned.
StartCopyAsync
is just a method to "start" copy process, you still need to monitor the copy state before deleting the blob. Please find my answer here for more details: How to get updated copy state of azure blob when using blob StartCopyAsync
Upvotes: 4
Reputation: 1725
Well, you have to await async
methods. StartCopyAsync fails, because you run a delete file call at the same time. Try using await
or Result
property.
var cred = new StorageCredentials("storageName", "Key");
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("containerName");
CloudBlockBlob sourceBlob = container.GetBlockBlobReference("folder/test.jpg");
//this doesn't work
await sourceBlob.StartCopyAsync(new Uri("destination url"));
//this works
await sourceBlob.DeleteAsync();
Code not tested, but should give you a general idea.
Upvotes: 2