当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlobClient.ListBlobsWithPrefix方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlobClient.ListBlobsWithPrefix方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobClient.ListBlobsWithPrefix方法的具体用法?C# CloudBlobClient.ListBlobsWithPrefix怎么用?C# CloudBlobClient.ListBlobsWithPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.StorageClient.CloudBlobClient的用法示例。


在下文中一共展示了CloudBlobClient.ListBlobsWithPrefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MoveDirectory

        private void MoveDirectory(CloudBlobClient blobClient, string newPrefix, string oldPrefix)
        {
            var blobs = blobClient.ListBlobsWithPrefix(oldPrefix,
                new BlobRequestOptions() { BlobListingDetails = Microsoft.WindowsAzure.StorageClient.BlobListingDetails.Metadata, UseFlatBlobListing = false });
            foreach (var blob in blobs)
            {
                if (blob is CloudBlobDirectory)
                {
                    var dir = blob as CloudBlobDirectory;

                    var names = dir.Uri.ToString().Split('/');
                    for (var i = names.Length - 1; i >= 0; i--)
                    {
                        if (!string.IsNullOrEmpty(names[i]))
                        {
                            MoveDirectory(blobClient, newPrefix + StorageNamesEncoder.EncodeBlobName(names[i]) + "/", oldPrefix + StorageNamesEncoder.EncodeBlobName(names[i]) + "/");
                            break;
                        }
                    }
                }
                else if (blob is CloudBlob)
                {
                    var cloudBlob = blob as CloudBlob;

                    if (cloudBlob.Exists())
                    {
                        cloudBlob.FetchAttributes();
                        var newContentBlob = blobClient.GetBlockBlobReference(newPrefix + cloudBlob.Metadata["FileName"]);
                        try
                        {
                            newContentBlob.CopyFromBlob(cloudBlob);
                        }
                        catch (Exception e)
                        {
                            using (Stream stream = new MemoryStream())
                            {
                                cloudBlob.DownloadToStream(stream);
                                stream.Position = 0;
                                newContentBlob.UploadFromStream(stream);
                                stream.Dispose();
                            }
                        }
                        newContentBlob.Metadata["FileName"] = cloudBlob.Metadata["FileName"];

                        if (!string.IsNullOrEmpty(cloudBlob.Metadata["UserId"]))
                        {
                            newContentBlob.Metadata["UserId"] = cloudBlob.Metadata["UserId"];
                        }
                        if (!string.IsNullOrEmpty(cloudBlob.Metadata["Published"]))
                        {
                            newContentBlob.Metadata["Published"] = cloudBlob.Metadata["Published"];
                        }
                        if (!string.IsNullOrEmpty(cloudBlob.Metadata["Size"]))
                        {
                            newContentBlob.Metadata["Size"] = cloudBlob.Metadata["Size"];
                        }
                        if (cloudBlob.Metadata.AllKeys.Contains("AlternateText"))
                        {
                            newContentBlob.Metadata["AlternateText"] = cloudBlob.Metadata["AlternateText"];
                        }
                        if (cloudBlob.Metadata.AllKeys.Contains("Description"))
                        {
                            newContentBlob.Metadata["Description"] = cloudBlob.Metadata["Description"];
                        }
                        if (cloudBlob.Metadata.AllKeys.Contains("Title"))
                        {
                            newContentBlob.Metadata["Title"] = cloudBlob.Metadata["Title"];
                        }

                        newContentBlob.SetMetadata();
                        cloudBlob.DeleteIfExists();
                    }
                }
            }
        }
开发者ID:Tsingbo-Kooboo,项目名称:KoobooMvc5,代码行数:75,代码来源:MediaFolderProvider.cs

示例2: zipFolder

        private void zipFolder(CloudBlobClient blobClient, string basePrefix, string folderName, string zipDir, ref ZipFile zipFile)
        {
            zipDir = string.IsNullOrEmpty(zipDir) ? folderName : zipDir + "/" + folderName;
            zipFile.AddDirectoryByName(zipDir);
            var folderPrefix = basePrefix + StorageNamesEncoder.EncodeBlobName(folderName) + "/";

            var blobs = blobClient.ListBlobsWithPrefix(folderPrefix,
            new BlobRequestOptions() { BlobListingDetails = Microsoft.WindowsAzure.StorageClient.BlobListingDetails.Metadata, UseFlatBlobListing = false });
            foreach (var blob in blobs)
            {
                if (blob is CloudBlobDirectory)
                {
                    var dir = blob as CloudBlobDirectory;

                    var names = dir.Uri.ToString().Split('/');
                    for (var i = names.Length - 1; i >= 0; i--)
                    {
                        if (!string.IsNullOrEmpty(names[i]))
                        {
                            zipFolder(blobClient, folderPrefix, StorageNamesEncoder.DecodeBlobName(names[i]), zipDir, ref zipFile);
                            break;
                        }
                    }
                }
                if (blob is CloudBlob)
                {
                    var cloudBlob = blob as CloudBlob;
                    var subStr = cloudBlob.Uri.ToString().Substring(cloudBlob.Uri.ToString().IndexOf(folderPrefix) + folderPrefix.Length);
                    var index = subStr.LastIndexOf('/');
                    if (index < 0)
                    {
                        index = 0;
                    }

                    var subFolderName = subStr.Substring(0, index);
                    var fileName = subStr.Substring(index);
                    var bytes = cloudBlob.DownloadByteArray();
                    if (!string.IsNullOrEmpty(subFolderName))
                    {
                        zipFile.AddDirectoryByName(zipDir + "/" + StorageNamesEncoder.DecodeBlobName(subFolderName));
                    }
                    zipFile.AddEntry(zipDir + "/" + StorageNamesEncoder.DecodeBlobName(subStr), bytes);
                }
            }
        }
开发者ID:Tsingbo-Kooboo,项目名称:KoobooMvc5,代码行数:45,代码来源:MediaFolderProvider.cs

示例3: MoveDirectory

        private void MoveDirectory(CloudBlobClient blobClient, string newPrefix, string oldPrefix)
        {
            var blobs = blobClient.ListBlobsWithPrefix(oldPrefix,
                new BlobRequestOptions() { BlobListingDetails = Microsoft.WindowsAzure.StorageClient.BlobListingDetails.Metadata, UseFlatBlobListing = false });
            foreach (var blob in blobs)
            {
                if (blob is CloudBlobDirectory)
                {
                    var dir = blob as CloudBlobDirectory;

                    var names = dir.Uri.ToString().Split('/');
                    for (var i = names.Length - 1; i >= 0; i--)
                    {
                        if (!string.IsNullOrEmpty(names[i]))
                        {
                            MoveDirectory(blobClient, newPrefix + names[i] + "/", oldPrefix + names[i] + "/");
                            break;
                        }
                    }
                }
                else if (blob is CloudBlob)
                {
                    var cloudBlob = blob as CloudBlob;

                    if (cloudBlob.Exists())
                    {
                        cloudBlob.FetchAttributes();
                        var newContentBlob = blobClient.GetBlockBlobReference(newPrefix + cloudBlob.Metadata["FileName"]);
                        newContentBlob.CopyFromBlob(cloudBlob);
                        newContentBlob.Metadata["FileName"] = cloudBlob.Metadata["FileName"];
                        newContentBlob.SetMetadata();
                        cloudBlob.DeleteIfExists();
                    }
                }
            }
        }
开发者ID:ZhiGuangHuang,项目名称:CMS,代码行数:36,代码来源:MediaFolderProvider.cs


注:本文中的Microsoft.WindowsAzure.StorageClient.CloudBlobClient.ListBlobsWithPrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。