Azure Blob Exists

by ingvar 14. december 2010 08:40

Here is a really simple way of determining of a blob exists or not. I have added the 'DebuggerStepThrough' attribute so my debugger won't break every time a blob does not exists.

public static class CloudBlobUtils
{
    [DebuggerStepThrough]
    public static bool Exists(this CloudBlob blob)
    {
        try
        {
            blob.FetchAttributes();
            return true;
        }
        catch (StorageClientException ex)
        {
            if (ex.ErrorCode == StorageErrorCode.ResourceNotFound)
            {
                return false;
            }

            throw;
        }
    }
}

Tags:

.NET | Azure | C# | Blob

Pingbacks and trackbacks (1)+

About the author

Martin Ingvar Kofoed Jensen

Architect and Senior Developer at Composite on the open source project Composite C1 - C#/4.0, LINQ, Azure, Parallel and much more!

Follow me on Twitter

Read more about me here.

Read press and buzz about my work and me here.

Stack Overflow

Month List