Gaurav
Gaurav

Reputation: 8487

How to rename the container name in windows azure?

Is there any way by which we can rename the blob container name in windows azure ?

Upvotes: 20

Views: 49511

Answers (5)

Nuri Tasdemir
Nuri Tasdemir

Reputation: 9842

This answer is not valid any more. It seems they removed this feature from "Microsoft Azure Storage Explorer"


Now, you can rename containers with Microsoft's "Microsoft Azure Storage Explorer" (after version 0.8.3). You can also rename azure tables and file shares with this tool. See the release notes here.

Note that this feature has the following disclaimer during usage.

Renaming works by copying to the new name, then deleting the source item. Renaming a blob container currently loses the container's properties and metadata, and may take a while if there are lots of blobs.

Therefore this is not an actual renaming behind the scenes and incurs read/write/transaction costs.

Upvotes: 28

Zenuka
Zenuka

Reputation: 3250

I couldn't find the rename functionality in the storage explorer v1.15.1 but I did use the clone option to create a copy and delete the old container.

Screenshot Microsoft Azure Storage Explorer

Upvotes: 5

Fernando Magno
Fernando Magno

Reputation: 441

No. You can't rename a blob container in Windows Azure.

Code to copy from the old storage to the new storage

AzCopy /Source:https://oldstorage.blob.core.windows.net/oldstorage /Dest:https://newstorage.blob.core.windows.net/newstorage /SourceKey:sourcekey /DestKey:destkey /S /XO

Upvotes: 1

Gaurav Mantri
Gaurav Mantri

Reputation: 136306

UPDATE

Please see answer from Nuri Tasdemir below.


No. You can't rename a blob container in Windows Azure. What you could do is create a new blob container with the new name and copy blobs from old blob container to the new one. Once the blobs are copied, you can delete the old blob container. Please note that if you're doing the copy blob in Cloud, this operation is asynchronous. So ensure that the blobs are copied completely before deleting the blob container.

Upvotes: 24

Manny Delarosa
Manny Delarosa

Reputation: 9

This RenameBlob method will allow you to rename folders or files in an Azure container.

  • album1/image1.jpg -> album2/image1.jpg
  • album1/image1.jpg -> album1/image2.jpg

HTH

public class AzureStorageService
{
    readonly CloudStorageAccount _storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

    public void RenameBlob(string oldName, string newName)
    {
        var blobClient = _storageAccount.CreateCloudBlobClient();
        var container = blobClient.GetContainerReference("MyContainer");

        var blobs = container.GetDirectoryReference(oldName).ListBlobs();

        foreach (var item in blobs)
        {
            string blobUri = item.Uri.ToString();

            var oldBlob = container.GetBlockBlobReference(blobUri);
            var newBlob = container.GetBlockBlobReference(blobUri.Replace(oldName, newName));

            newBlob.StartCopyFromBlob(oldBlob);

           oldBlob.Delete();
        }
    }
}

Upvotes: -4

Related Questions