I made a solution for a customer where I copied blobs from Windows Azure Blobstorage to an different location on Windows Azure Blobstorage. But to be a bit efficient I was keeping a list of blobs I have copied already. This list contains a Last modified date. So I the Last modified date was not changed I did not copy etc.
Smart and at first it looked rater simple. Take a Blob look at the property LastModifiedUtc and voila.
blockBlob.Properties.LastModifiedUtc
So with a blob I look in the list compare the LastModifiedUtc of the Blob with the one in the list. In case those were equal I did nothing otherwise I copied it to the new location.
But during testing I found out that after a new upload op my blob (changing the Modified date), the copy action did not execute. And when I debugged I found the value of LastModifiedUtc was always zero. Strange because my Cerebrata Storage tool could see the differences. So why not me.
The solution was very simple. Before checking the properties, do a FetchAttributes on the Blob and voila the property is valid.
CloudBlockBlob blockBlob = _sourceContainer.GetBlockBlobReference(uri.ToString()); blockBlob.FetchAttributes();
To make my solution way smarter I kept the list in a Windows Azure Table storage. But ths will be in a later post.