c# - How to check if Azure Blob file Exists or Not -
i want check particular file exist in azure blob storage. possible check specifying it's file name? each time got file not found error.
this extension method should you:
public static class blobextensions { public static bool exists(this cloudblob blob) { try { blob.fetchattributes(); return true; } catch (storageclientexception e) { if (e.errorcode == storageerrorcode.resourcenotfound) { return false; } else { throw; } } } }
usage:
static void main(string[] args) { var blob = cloudstorageaccount.developmentstorageaccount .createcloudblobclient().getblobreference(args[0]); // or cloudstorageaccount.parse("<your connection string>") if (blob.exists()) { console.writeline("the blob exists!"); } else { console.writeline("the blob doesn't exist."); } }
http://blog.smarx.com/posts/testing-existence-of-a-windows-azure-blob
Comments
Post a Comment