Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除C#-中子文件夹中的Azure Blob,而不删除子文件夹_C#_Azure_Azure Storage_Azure Storage Blobs - Fatal编程技术网

删除C#-中子文件夹中的Azure Blob,而不删除子文件夹

删除C#-中子文件夹中的Azure Blob,而不删除子文件夹,c#,azure,azure-storage,azure-storage-blobs,C#,Azure,Azure Storage,Azure Storage Blobs,我有一个Azure容器“MyContainer”,然后在它下面有一个叫做ProcessingFiles的“子文件夹”。所以“结构”看起来像这样 MyContainer\ProcessingFiles\SampleFile.xml 我想删除“SampleFile.xml”-但是当我运行以下代码时,“ProcessingFiles”文件夹也会被删除 //connect to azure container var storageAccount = CloudStorage

我有一个Azure容器“MyContainer”,然后在它下面有一个叫做ProcessingFiles的“子文件夹”。所以“结构”看起来像这样

MyContainer\ProcessingFiles\SampleFile.xml

我想删除“SampleFile.xml”-但是当我运行以下代码时,“ProcessingFiles”文件夹也会被删除

 //connect to azure  container
            var storageAccount = CloudStorageAccount.Parse(_BlobConnectionstring);

            var myClient = storageAccount.CreateCloudBlobClient();
            var container = myClient.GetContainerReference(MyContainer");

            container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);

            _blobabspath = container.Uri.AbsoluteUri;

            foreach (IListBlobItem blobItem in container.ListBlobs())
            {
                if (blobItem is CloudBlobDirectory)
                {
                    CloudBlobDirectory directory = (CloudBlobDirectory)blobItem;
                    if (directory.Uri.AbsoluteUri.Contains("ProcessingFolder))
                    {
                        IEnumerable<IListBlobItem> blobs = directory.ListBlobs(true);
                        ICloudBlob bi;
                        foreach (var blob in blobs)
                        {
                            if (blob is CloudBlockBlob)
                            {
                                bi = blob as CloudBlockBlob;
                                if (bi.Name.Contains(".xml"))
                                {
                                   Log.Info($"Deleting XML file : {bi.Name} from {_processingfolder}");
                                   bi.Delete();
                                }
                            }
                        }
                    }
                }
            }
//连接到azure容器
var storageAccount=CloudStorageAccount.Parse(_BlobConnectionstring);
var myClient=storageAccount.CreateCloudBlobClient();
var container=myClient.GetContainerReference(MyContainer”);
CreateIfNotExists(BlobContainerPublicAccessType.Blob);
_blobabspath=container.Uri.AbsoluteUri;
foreach(容器中的IListBlobItem blobItem.ListBlobs())
{
if(blobItem是CloudBlobDirectory)
{
CloudBlobDirectory目录=(CloudBlobDirectory)blobItem;
if(directory.Uri.AbsoluteUri.Contains(“ProcessingFolder))
{
IEnumerable blobs=directory.ListBlobs(true);
ICloudBlob-bi;
foreach(blob中的var blob)
{
if(blob是CloudBlockBlob)
{
bi=作为CloudBlockBlob的blob;
if(bi.Name.Contains(“.xml”))
{
Log.Info($“从{u processingfolder}删除XML文件:{bi.Name}”);
bi.Delete();
}
}
}
}
}
}
如何删除单个XML文件,而不包括子文件夹“ProcessingFolder”?


我错过了什么?thx预付款

Azure存储没有子文件夹,只有容器和Blob。Azure存储通过分隔符为您提供了类似于文件夹的内容(例如,允许您执行特定搜索)

您的blob的名称实际上是
ProcessingFiles\SampleFile.xml
。这就是为什么删除blob时子文件夹会消失的原因

为了进一步说明这一点:假设您有一千个blob,分布在多个“子文件夹”中,并且您尝试只在一个子文件夹上进行筛选(
ProcessingFiles
)。搜索仍将扫描所有1000个blob,并在指定名称的前缀部分进行过滤