Anyway, the following is the code to create a blob and create folder in the blob. The code will upload a text file to Data2 folder in the logdata1 container in the Azure blob.
class Program
{
static void Main(string[] args)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=<account name>;AccountKey=<account key>");
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference("logdata1");
container.CreateIfNotExists();
var fn = "Data2/TextFile1.txt";
var blob = container.GetBlockBlobReference(fn);
//upload file to container
using (var fileStream = System.IO.File.OpenRead("TextFile1.txt"))
{
blob.UploadFromStream(fileStream);
}
//list items in the container
var blobs = container.ListBlobs();
foreach (var b in blobs)
{
Console.WriteLine(b);
}
}
}
No comments:
Post a Comment