Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Azure – Copy Blob from one container to another container

Viewed:  838 
Posted On:  22/09/2019 08:51:51 
How we can move Blob from one container to another container in Azure?  

In this article, I am going to show, how we can move blob from one container to another container.

For this, I am going to use a console application.

Open VS2017 -> File -> New Project ->


Image 1.

Now right click on Project Solution Explorer -> Manage NuGet


Image 2. 

Now open your App.config and add below keys:

<?xml version="1.0" encoding="utf-8" ?>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />

    <add key="SourceStorageConnectionString" value="YourCS" />
    <add key="DestinationStorageConnectionString" value="YourCS" />
    <add key="SourceContainer" value="source" />
    <add key="DestinationContainer" value="destination" />


Get your Storage Account connection string from your Azure Portal.


Image 3.

Here I have a Storage account "storageaccountonetest"

Inside this in Blob I have 2 Container

  1.  source
  2. Destination


Image 4.

Now see files inside source container.


Image 5.

Currently there is no Blob in destination.


Image 6.

Now do below code in Program.cs file:

using System;
using System.Collections.Generic;

using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.IO;
using Microsoft.Azure;
namespace ManageAzureBlob
    class Program
        static void Main(string[] args)
            //Get source azure storage account connection string from app.config
            CloudStorageAccount sourceStorageConnectionString =

            //Get destination azure storage account connection string from app.config
            CloudStorageAccount destinationStorageConnectionString =

            CloudBlobClient sourceCloudBlobClient = sourceStorageConnectionString.CreateCloudBlobClient();
            CloudBlobClient targetCloudBlobClient = destinationStorageConnectionString.CreateCloudBlobClient();

            //Get source and destination container name from app.config
            CloudBlobContainer sourceContainer = sourceCloudBlobClient.GetContainerReference(CloudConfigurationManager.GetSetting("SourceContainer"));
            CloudBlobContainer destinationContainer =


            //Create Destination container into blob if not exists

            // Loop over items within the container and output the length and URI.
            foreach (IListBlobItem item in sourceContainer.ListBlobs(null, false))
                if (item.GetType() == typeof(CloudBlockBlob))
                    CloudBlockBlob blob = (CloudBlockBlob)item;
                    Console.WriteLine("Block blob of length {0}: {1}", blob.Properties.Length, blob.Uri);
                    Console.WriteLine("Started moving blob: " + blob.Name + " from container " + sourceContainer.Name + "  to " + destinationContainer.Name);
                    CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(blob.Name);
                    CloudBlockBlob targetBlob = destinationContainer.GetBlockBlobReference(blob.Name);
                    //copy blob from source to destination
                    //check if blob exists into destination container
                    if (targetBlob.Exists())
                        //Delete blob from source container
                else if (item.GetType() == typeof(CloudPageBlob))
                    CloudPageBlob pageBlob = (CloudPageBlob)item;
                    Console.WriteLine("Page blob of length {0}: {1}", pageBlob.Properties.Length, pageBlob.Uri);
                    Console.WriteLine("Started moving blob: " + pageBlob.Name + " from container " +
                                                                                                                            sourceContainer.Name +
"  to " +destinationContainer.Name);
                    CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference(pageBlob.Name);
                    CloudBlockBlob targetBlob = destinationContainer.GetBlockBlobReference(pageBlob.Name);
                    if (targetBlob.Exists())

                else if (item.GetType() == typeof(CloudBlobDirectory))
                    CloudBlobDirectory directory = (CloudBlobDirectory)item;
                    Console.WriteLine("Directory: {0}", directory.Uri);
            Console.WriteLine(" Blob moved has been successfully.");

Now run your application:


Image 7.

Now check your destination container.


Image 8.

View your Blob:


Image 9.

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us