private readonly CloudBlobContainer _blobContainer; public void Remove() { if (_blobContainer.Exists()) { _blobContainer.Delete(); } }
如何删除整个容器而不是一些List< string>容器中的磁盘?
解决方法
这是我使用的代码:
private CloudBlobContainer blobContainer; public void DeleteFile(string uniqueFileIdentifier) { this.AssertBlobContainer(); var blob = this.blobContainer.GetBlockBlobReference(fileName); blob.DeleteIfExists(); } private void AssertBlobContainer() { // only do once if (this.blobContainer == null) { lock (this.blobContainerLockObj) { if (this.blobContainer == null) { var client = this.cloudStorageAccount.CreateCloudBlobClient(); this.blobContainer = client.GetContainerReference(this.containerName.ToLowerInvariant()); if (!this.blobContainer.Exists()) { throw new CustomRuntimeException("Container {0} does not exist in azure account",containerName); } } } } if (this.blobContainer == null) throw new NullReferenceException("Blob Empty"); }
显然,你有blobContainer的东西排序,所以你需要的是没有this.AssertBlobContainer()的DeleteFile方法.