Skip to content

Instantly share code, notes, and snippets.

@robertgreiner
Created September 26, 2013 18:43
Show Gist options
  • Save robertgreiner/6718704 to your computer and use it in GitHub Desktop.
Save robertgreiner/6718704 to your computer and use it in GitHub Desktop.
How to write text to a CloudBlockBlob in Windows Azure
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("AzureStorageAccount"));
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
container.CreateIfNotExists();
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
blob.DeleteIfExists();
var options = new BlobRequestOptions()
{
ServerTimeout = TimeSpan.FromMinutes(10)
};
using (var stream = new MemoryStream(Encoding.Default.GetBytes(text), false))
{
blob.UploadFromStream(stream, null, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment