我想从azure blob存储中读取文件。文件夹中的文件。 Blob存储包含许多文件夹。我想读取我的文件夹“ blobstorage”,其中包含许多json文件。读取每个文件并执行一些操作。我尝试许多代码在我的情况下对任何代码都不起作用。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference($"blobstorage");
以上代码使用'Microsoft.WindowsAzure.Storage'nuget包。此代码无法正常工作在堆栈溢出中发现的许多问题和答案中,大多数都已过时且无法正常工作。注意:如果有任何提及,也有bcs的话,它们是很多软件包
我看不到使用Microsoft.WindowsAzure.Storage
软件包列出所有Blob的选项。如果可以使用Azure.Storage.Blobs
软件包,请尝试以下代码。
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using System;
namespace ConsoleApp2
{
class Program
{
static string connectionString = "DefaultEndpointsProtocol=https;AccountName=storage******c9709;AccountKey=v**************************************;EndpointSuffix=core.windows.net";
static string container = "azure-webjobs-hosts";
static void Main(string[] args)
{
// Get a reference to a container named "sample-container" and then create it
BlobContainerClient blobContainerClient = new BlobContainerClient(connectionString, container);
blobContainerClient.CreateIfNotExists();
Console.WriteLine("Listing blobs...");
// List all blobs in the container
var blobs = blobContainerClient.GetBlobs();
foreach (BlobItem blobItem in blobs)
{
Console.WriteLine("\t" + blobItem.Name);
}
Console.Read();
}
}
}
输出
您也可以下载blob的内容,请检查此link