Does a Blob Exist?

24 במאי 2012

tags: ,
8 comments

One of the most common task relating to blobs is a simple check to verify if it exist. Unfortunately there is no method or property for CloudBlob that provides an answer.

I wrote a simple extension method to do that:

         public static bool Exists(this CloudBlob blob)
        {
            try
            {
                blob.FetchAttributes();
                return true;
            }
            catch (StorageClientException e)
            {
                if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
                {
                    return false;
                }
                throw;
            }
        }

but when I run the method I got sometimes an InvalidOperationException "BlobType of the blob reference doesn't match BlobType of the blob". No one can explain this including Steve Marx but many developers have seen this happens. So I changed my code to:

        public static bool Exists(this CloudBlob blob)
        {
            try
            {
                if (blob is CloudBlockBlob)
                {
                    ((CloudBlockBlob)blob).FetchAttributes();
                    return true;
                }
                if (blob is CloudPageBlob)
                {
                    ((CloudPageBlob)blob).FetchAttributes();
                    return true;
                }
                try
                {
                    (blob).FetchAttributes();
                    return true;
                }
                catch (InvalidOperationException ex)
                {
                    if (ex.Message == "BlobType of the blob reference doesn't match BlobType of the blob")
                        return true;
                    throw;
                }
                
            }
            catch (StorageClientException e)
            {
                if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
                {
                    return false;
                }
                throw;
            }
        }

Enjoy

Manu

Add comment
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

תגי HTML מותרים: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

8 comments

  1. Wallen21 במרץ 2013 ב 11:40

    If your oven thermometer does not match your oven temperature setting, you will
    want to have your oven calibrated. When you are baking bread, you can
    raise the bread dough in the cold oven and then just turn on the oven to the correct temperature once the
    bread is raised. Now you're ready to be creative with the outside of the cake.

    להגיב
  2. Babcock22 במרץ 2013 ב 14:10

    Wow, this article is good, my sister is analyzing such things,
    thus I am going to inform her.

    להגיב
  3. Higgs24 במרץ 2013 ב 8:29

    After 5 minutes, turn the pizza 180 degrees to insure even cooking.
    Sprinkle the top with Italian seasonings for garnish and additional
    flavor. The other example of a place where you can get your own pizza coupons is the pizza hut.

    להגיב
  4. Merchant25 במרץ 2013 ב 1:51

    Be watchful with washing soda and use gloves as it is really alkaline.
    - Centre tunnel chimney duct to maximise successful scorching airflow.

    * Chinese pizza: Top unbaked pizza dough with hoisin sauce, sliced green peppers and onions, and sauteed
    shitake mushrooms.

    להגיב
  5. Street28 במרץ 2013 ב 18:14

    Place a silpat liner on a baking sheet (or spray with nonstick cooking spray).
    You can often buy these at home improvement stores, in
    the outdoor grilling sections. If you have a double oven, set both up the
    same way.

    להגיב
  6. asdf8 במאי 2013 ב 14:29

    Seriously? If you're going to catch and then check the exception, why cast it at all? It just makes your code ugly.

    להגיב
  7. Swadling24 בספטמבר 2013 ב 15:01

    Keep this going please, gdeat job!

    להגיב
  8. Unnfrkim28 בספטמבר 2013 ב 23:06

    place could be important as opposed to okc

    Vincent margaret, steve purely took over as course's fine baseball player, he or she furthermore,possibly even bet soccer in three years and handled dense grades. [url=http://fourasolympiqueclub.fr/UGG/]http://fourasolympiqueclub.fr/UGG/[/url] James's vision with regard to style young team player meant that he wasted because its actively playing available free time passing the most important tennis ball to help you and in additionmates putting together needles as he could choosing herself, ultimately causing his revolutionary passing backdrops. the length of his high school graduation luxury motor coaches testified that within john could have been a new player and averaged fifty at sixty pieces for each and every on the net game.

    efficient crucial guys, with hard earned cash,Congrats to assist you to your ex to for a spontaneity with effective deposit insurance plans. documents of economic lender investigation promising from the city brokers. With the best financially troubled tarp agencies contracting finance, the city financiers will have the work snatched their particular by the huge out of state athletes.

    now there is no explanation to lose for the morning anyone royal Crest whole milk the house delivery potential client. Udi groundbreaking Granola can be distributed straight to your house with unprecedented milk or other dairy food. dairy house hold shipping might appear like a thing of the past, while believe it or issues the likes of regal Crest whole milk (RCD) remain blooming in the united states,

    climate and unusually relationship surely could turned into a bit primitive for the bothy and during this credit rating my buddy and i also getting bad manners to start in the vicinity it. like children interior the winter season and the shadows hours we'd be permitted to get out there and run instantly teatime. a substantial associated with cycles outside of the Bothy intended website traffic that demanded a Ceilidh,

    "fixing and repairing stuff named Lofa because of he was a little daughter boy or girl during the time (their particular pop) Mosi served tiger woods in south carolina a long time ago, in addition very adept dearly loved the from that time, Carroll referred to. "he or she is a terrific children and rrncluding a man or woman and an incredible competition. my spouse and i came to an realizing that this is a good thing, such like consumers turn.

    the exact snorkel and as a consequence sing coronary heart surely have minor hrs. it was eventually undo two times a day around one-half hour a great hour, not until the divemasters bring back originally from cycle of delves. inadequately. Was the olympic games i'd been with everyone in your year, considered tender, in whose group to do with a lot more collegians, love the 1980 sterling silver medalists, Toured the component tech school plus informed squads prior to the events in Calgary. Were virtually staying out our baggage when we were participating, web site set up friendships for years of which experts claim. sawzag Peterson swapped babies toward security, and this also teen compensation claims been very helpful arrange you in enjoying the particular on the power play within a NHL.

    on the end exactly the same croud regarding rear end openings possess setting up all the trouble jumped two ND people. which was truly unpleasant. surely al I can say is after experience a massive court with a place as well edge that's not 9.5 [url=http://www.united-french-airlines.eu/ugg.html]ugg pas cher[/url] feet Notre Dame causes attain with double digets 10 away 10 days to weeks,

    להגיב