c# – 如何从blob容器中删除文件?

前端之家收集整理的这篇文章主要介绍了c# – 如何从blob容器中删除文件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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方法.

猜你在找的C#相关文章