3

I am trying to create a new C# console application that writes into the blob storage directly from the code. I am able to create a local file and upload it to the blob. But the requirement is writing the content directly to blob instead of creating a file and uploading to Blob.I am not being able to achieve this. I searched for the related web resources but couldn't find anything that would help in this issue. I am looking for suggestions/help.

CSK
  • 67
  • 3
  • 11

1 Answers1

4

It's actually pretty straight forward. See the code below:

    static void SaveTextAsBlob()
    {
        var storageAccount = CloudStorageAccount.Parse("storage-account-connection-string");
        var blobClient = storageAccount.CreateCloudBlobClient();
        var container = blobClient.GetContainerReference("container-name");
        var blob = container.GetBlockBlobReference("blob-name.csv");
        blob.Properties.ContentType = "text/csv";
        string blobContents = GetCsvTextSomehow();
        blob.UploadText(blobContents);
    }
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241