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.
Asked
Active
Viewed 5,343 times
3
-
What kind of data you’re trying to save? Is it text? – Gaurav Mantri May 20 '19 at 11:48
-
1Possible duplicate of [How do I save byte arrays i.e. byte\[\] to Azure Blob Storage?](https://stackoverflow.com/questions/15115212/how-do-i-save-byte-arrays-i-e-byte-to-azure-blob-storage) – Peter B May 20 '19 at 11:51
-
@GauravMantri Yes, its csv content. – CSK May 20 '19 at 12:02
1 Answers
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