Saturday, January 21, 2012

How to Rename a blob on Azure


I came across something today that I think it is good to share, blob names are case-sensitive in windows Azure. So I had to write a program to rename all blobs and change them to lower case. here is the code.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace MyBlobRenameApp
{
    public class Process
    {
        private static void RenameBlobs()
        {
            string blobConName = ConfigHelper.BlobContainerName;

            string dataCenterSettingKey = "DefaultEndpointsProtocol=" + 
                                           ConfigHelper.DefaultEndpointsProtocol +
                                          ";AccountName=" + 
                                          ConfigHelper.AccountName +
                                          ";AccountKey=" + 
                                          ConfigHelper.AccountKey;

            CloudStorageAccount cloudStorageAccount = 
                                  CloudStorageAccount.Parse(dataCenterSettingKey);

            CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();

            CloudBlobContainer container = 
                                   blobClient.GetContainerReference(blobConName);
            // Create the container if it does not exist.
            container.CreateIfNotExist();

            // Set permissions on the container.
            BlobContainerPermissions permissions = new BlobContainerPermissions();

            containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
            container.SetPermissions(permissions);

           //For example we have 2 blobs VSN/b1 and VSN/b2
            var blobs = container.GetDirectoryReference("VSN").ListBlobs();
            foreach (var item in blobs)
            {
                string blobUri = item.Uri.ToString();

                CloudBlob existBlob = container.GetBlobReference(blobUri);
                CloudBlob newBlob = container.GetBlobReference(blobUri.ToLower());

                newBlob.CopyFromBlob(existBlob);

                existBlob.Delete();
            }
        }
    }
}


Hopefully this post will be useful to somebody who runs into the same problem.

56 comments:

AndrewK said...

Thanks a lot for example.

Alex said...

I believe this could be simplified slightly.

Instead of getting blob reference by passing in the Uri you can just cast the collection of IListBlogItem to CloudBlob because CloudBlob inherits from IListBlogItem.

foreach (var existBlob in blobs.ToList().Cast<CloudBlob>())
{
var newBlob = container.GetBlobReference(existBlob.Name.ToLower());
newBlog.CopyFromBlob(existBlob);
existBlob.Delete();
}

Hope that helps :)

jvongillern said...

In v2 of the api, CopyFromBlob changed to StartCopyFromBlob, so it is possible that the delete will finish before the copy does and you'll end up losing data. It caused me some pain so I wanted to spread the word. Writeup: http://stackoverflow.com/questions/3734672/azure-storage-blob-rename/26549519#26549519

mist hyderabad said...

Thank u for this information
http://www.mistltd.com

gautham said...

microsoft azure is a cloud and open source platform for client SDK. It is a cloud computing service created by microsoft for building and developing apps. learn more in azure training in hyderabad

iAppSoft Solutions said...

Great blog created by you. I read your blog, its best and useful information.
AWS Online Training
Devops Online Training
Apllication Packaging Online Training

gautham said...

Azure is technology which works on cloud development. learn azure through azure certification

gautham said...

haddop have to Develop and implement Hadoop applications from scratch hadoop certification

svrtechnologies said...

Thanks for the Informative Post...

amazon web services tutorial

Unknown said...

best angular js online training
top angular js online training
angular js online training

svrtechnologies said...

Whatever we gathered information from the blogs, we should implement that in practically then only we can understand that exact thing clearly, but it’s no need to do it on azure online training , because you have explained the concepts very well. It was crystal clear, keep sharing..

svrtechnologies said...

This post is really nice and informative. The explanation given is really comprehensive and useful.
learn data science online

svrtechnologies said...

This is so elegant and logical and clearly explained. Brilliantly goes through what could be a complex process and makes it obvious.

hadoop tutorial for beginners

Blogger said...

Water Hack Burns 2 lb of Fat OVERNIGHT

Over 160000 women and men are trying a easy and SECRET "liquids hack" to burn 1-2lbs each and every night as they sleep.

It is scientific and it works every time.

Here's how you can do it yourself:

1) Go get a glass and fill it up half the way

2) And then do this crazy hack

you'll become 1-2lbs skinnier when you wake up!

varsha said...

Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
AWS training in chennai | AWS training in anna nagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery

nandhini said...

That was a very informative post. Thank you so much. Keep posting more..
Microsoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune

keerthana said...

Thank you so much informative post.
PHP Training in Chennai | Certification | Online Training Course | Machine Learning Training in Chennai | Certification | Online Training Course | iOT Training in Chennai | Certification | Online Training Course | Blockchain Training in Chennai | Certification | Online Training Course | Open Stack Training in Chennai |
Certification | Online Training Course

dexterous said...

Very interesting post,
thanks for shearing with us.
GMAT online Training
GMAT coaching in hyderabad

dhinesh said...

An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening.


Full Stack Course Chennai
Full Stack Training in Bangalore

Full Stack Course in Bangalore

Full Stack Training in Hyderabad

Full Stack Course in Hyderabad

Full Stack Training

Full Stack Course

Full Stack Online Training

Full Stack Online Course



Jobi said...

Fantastic blog i have never ever read this type of amazing information.
george michael leather jacket

OGEN Infosystem (P) Limited said...

Great, I personally like this blog. Visit Ogen Infosystem for creative eCommerce website designing and PPC services at the best price in Delhi.
PPC Company in Delhi

Jon Hendo said...

Thanks mate. I am really impressed with your writing talents and also with the layout on your weblog. Appreciate, Is this a paid subject matter or did you customize it yourself? Either way keep up the nice quality writing, it is rare to peer a nice weblog like this one nowadays. Thank you, check also event marketing and Tips to Organize Private Event Virtually

Amrita Bansal said...

Prefer to study this kind of material. Nicely written information in this post, the quality of content is fine and the conclusion is lovely.
Data science training
Data Analytics Training
Devops training
Selenium training

Quickbooks Expert said...

Nice post!

Worried About QuickBooks Error ?Get in touch with QuickBooks expert for instant solution.
Click Here to know how to fix QuickBooks Form 941 Error

Dial on QuickBooks Error Support Phone Number +1-855-977-7463.

Josh said...

Best IT Training Institute in chennai, Drilling consultants

Amrita Bansal said...

Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.

Power Bi Training in Gurgaon
SQL Training in Gurgaon
Advanced Excel /VBA training in Gurgaon

New Games said...

This is Very very nice article. Everyone should read. Thanks for sharing. Don't miss WORLD'S BEST GAME 👉 BikeRaceGame

QuickBooks Error said...

Nice Blog !
QuickBooks Error 248 can occur when a user tries to run payroll for the employees. You may also encounter this issue when you are taking a backup of your company file.call us and get the best possible solutions to resolve QuickBooks Error 248.

Anonymous said...

learn from experts

aisha singh said...

Due to the rising demand for Data Scientists, there are many educational platforms that are coming up with programs in Data Science, you may never find the best, but you can always find the one that is suitable for you.

Data Science Training in Gurgaon

palak jaswal said...

Data Science Training in Gurgaon is the study of data. It involves developing methods of recording, storing, and analyzing data to effectively extract useful information. The goal of data science is to gain insights and knowledge from any type of data — both structured and unstructured.
Data Science Training in Gurgaon
Bigdata Hadoop Training in Gurgaon
Devops Training in Gurgaon

Priya Rathod said...

I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates new hope and inspiration within me. Thanks for sharing an article like this. the information which you have provided is better than another blog.
AWS Training in Hyderabad
AWS Course in Hyderabad

Customer Support | Live Chat Service said...

How do I fix Yahoo mail not working on Mac?

Sometimes pernicious software can enter into your system when you download any software unintentionally. Such malware can stop the working of apps like your Browser and Mac Mail. In such a case, you need to scan your Mac with an excellent antivirus to confirm the suspicion to fix the Yahoo mail not working on Mac issue.

Also Read:-

yahoo mail not syncing
how do i talk to a person at verizon customer service
how do i speak to a live person at google
my facebook is not working


Nobody said...

motogp leather suits

Unknown said...

aşk kitapları
youtube abone satın al
cami avizesi
cami avizeleri
avize cami
no deposit bonus forex 2021
takipçi satın al
takipçi satın al
takipçi satın al
takipcialdim.com/tiktok-takipci-satin-al/
instagram beğeni satın al
instagram beğeni satın al
btcturk
tiktok izlenme satın al
sms onay
youtube izlenme satın al
no deposit bonus forex 2021
tiktok jeton hilesi
tiktok beğeni satın al
binance
takipçi satın al
uc satın al
sms onay
sms onay
tiktok takipçi satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
instagram beğeni satın al
tiktok beğeni satın al
twitter takipçi satın al
trend topic satın al
youtube abone satın al
takipcialdim.com/instagram-begeni-satin-al/
perde modelleri
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
betboo
marsbahis
sultanbet

cloudbeginners said...

world777 official

aaryan said...

aws solution architect training
azure solution architect certification
openshift certification
azure data engineer certification

eddielydon said...

Nice post. Thank you to provide us this useful information. 49ers varsity jacket

George Mark said...

Incredible blog here! It's mind boggling posting with the checked and genuinely accommodating data. Selena Astros Jacket

Historical Jacket Shop said...

Awesome Blog.. its Historical Jackets For Sale

Hussar Dolman Jackets For Sale

Hussar Military Jackets For Sale

Military Parade Jackets For Sale

tektutes said...

Very Nice Blog…Thanks for sharing this information with us. Here am sharing some information about training institute.
tableau training in hyderabad

Gerry Max said...

Despite its unique features and functions, sometimes it is difficult to log in. If you find that the Protonmail account temporarily unavailable, then this is because there is anything that looks like an attempt by an attacker to access your account. Protonmail's security system will automatically identify and flag it. When you are at high risk, Protonmail may also temporarily lock your account to prevent the attacker from accessing it. Protonmail Login Problem

Unknown said...

tiktok jeton hilesi
tiktok jeton hilesi
binance referans kimliği
gate güvenilir mi
tiktok jeton hilesi
paribu
btcturk
bitcoin nasıl alınır

Gerry Max said...

When you forget your Yahoo password, you can reset it to regain access to your account. You can use your Yahoo password to access every Yahoo service you use. Despite the iPhone's default web browser being Safari, you can download and install the Yahoo Mail app so you can change the password. To change password Yahoo mail on iPhone, launch the Yahoo Mail app and enter the correct login credentials and tap on "Login." On the iPhone, tap the Menu icon and tap "Manage Accounts."

Gerry Max said...

There are ways to disable Google Voice or unsubscribe completely. However, one thing to keep in mind is that if you use Google Voice with an existing Sprint account or service, or if you paid Sprint to transfer your number, you won't be able to delete it. Furthermore, deleting your Google Voice number will not erase your account's data so that messages will remain in your inbox. To learn how to delete Google voice number on iPhone, you need to go into the settings and select "Phone." Once you're in the Voicemail menu, choose "Voicemail" and then tap on the arrow next to the number you want to delete. Then, click "Delete," and then confirm your choice.

mirror said...

Thanks for sharing this post.project center in chennai

lakshmi said...

Thanks for the Informative Post...
visit: -swhizz

Rubel hossen said...

wordpress website design agency in united states Need professional WordPress Web Design Services? We're experts in developing attractive mobile-friendly WordPress websites for businesses. Contact us today!

Mahil mithu said...


Nice Blog...! It is really useful for me and I expect from you more updating about this title. Thank you!!!
Spousal Support Calculator
Spousal Support Virginia

Hashini said...

Great post and I know more details from this article. Thank you!
pvc foam board manufacturers in kerala

shazam said...

Absolutely informative blog
Contratos Comerciales Disputas
Contratos Disputas Litigio

TRONIX said...

Nice Information Your first-class knowledge of this great job can become a suitable foundation for these people.
Python training institution in Hyderabad

The Dark Attitude said...

Thanks for sharing this valuable information with us.
Punk Rock Pants

schnauzer said...

https://furkittens.com/cat-persian-for-sale/

https://furkittens.com/for-sale-maine-coon-kitten/
https://greenlandpuppies.com/
https://greenlandpuppies.com/teacup-yorkie-for-sale/

https://greenlandpuppies.com/teacup-poodle-puppies-for-sale/
https://frenchbulldogspuppiesforsale.com/
https://furkittens.com/

Go India Tour and Cabs said...

Go India Tour and Cabs leads in providing Taxi service in Jaipur that offers the most luxurious and reasonably priced taxi trips in world-class vehicles. We offer cab in Jaipur travel, outstation trips, weddings, corporate events, airport services, and sightseeing in Jaipur.

vv software said...

Good explanation about the .Net I loved it
Keep posting more

Post a Comment