本文整理汇总了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();
}
}
}
}
示例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);
}
}
}
示例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();
}
}
}
}