none
Copy Blob from one storage account to another in Azure

    Question

  • I have One blob which contains My user's CVs.

    My site is live. Now i want to copy From one blob to another blob with different storage account. 

    here is my code to copy blob

    CloudStorageAccount sourceStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("sourceStorageConnectionString"));
    CloudStorageAccount targetStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("targetStorageConnectionString"));

                CloudBlobClient sourceCloudBlobClient = sourceStorageAccount.CreateCloudBlobClient();
                CloudBlobClient targetCloudBlobClient = targetStorageAccount.CreateCloudBlobClient();

                CloudBlobContainer sourceContainer = sourceCloudBlobClient.GetContainerReference(CloudConfigurationManager.GetSetting("sourceContainer"));
                CloudBlobContainer targetContainer = targetCloudBlobClient.GetContainerReference(CloudConfigurationManager.GetSetting("targetContainer"));
                targetContainer.CreateIfNotExists();

                // Copy each blob
                foreach (IListBlobItem blob in sourceContainer.ListBlobs(useFlatBlobListing: true))
                {

                    Uri thisBlobUri = blob.Uri;

                    var blobName = Path.GetFileName(thisBlobUri.ToString());
                    Console.WriteLine("Copying blob: " + blobName);

                    CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(blobName);
                    CloudBlockBlob targetBlob = targetContainer.GetBlockBlobReference(blobName);

                    Task task = TransferManager.CopyAsync(sourceBlob, targetBlob, true /* isServiceCopy */);

                }

    but my concern is: If this copy operation is running and one of the Cv is updated by any user then will it be effect on live site or in copy operation???

    And also will this code is correct for copy blob?

    Please help me out for this problem..

    Thanks in advance,

    Maitri 

    • Moved by Sabah ShariqMVP Monday, February 6, 2017 1:20 PM Moved From Visual C#
    Monday, February 6, 2017 9:39 AM

All replies

  • Hi Maitri,

    Hi,

    This is Visual C# forum. As your issue is related to Azure I am moving your thread to Azure Storage forum for getting quick response.

    Your understanding and cooperation will be grateful.


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Monday, February 6, 2017 1:20 PM
  • Looks like your question that was also posted on StackOverflow has been answered. You can post back here if you have any further questions.

    --------------------------------------------------------------------------------------------

    Md. Shihab


    • Edited by Md Shihab Tuesday, February 7, 2017 4:11 AM
    • Proposed as answer by Md Shihab Sunday, February 12, 2017 9:49 AM
    Tuesday, February 7, 2017 4:11 AM