Skip to content

Instantly share code, notes, and snippets.

@RichardSlater
Created November 24, 2012 16:42
Show Gist options
  • Save RichardSlater/4140439 to your computer and use it in GitHub Desktop.
Save RichardSlater/4140439 to your computer and use it in GitHub Desktop.
Find any string and replace with any other string in an Azure Table Storage Blob
var accountName = Properties.Settings.Default.StorageAccountName;
var accountKey = Properties.Settings.Default.AccessKey;
var containerName = Properties.Settings.Default.ContainerName;
var blobName = Properties.Settings.Default.Blob;
var credentials = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(credentials, useHttps: true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference(containerName);
var blob = container.GetBlockBlobReference(blobName);
string content;
using (var source = new MemoryStream())
{
blob.DownloadToStream(source);
using (var reader = new StreamReader(source))
{
source.Seek(0, SeekOrigin.Begin);
content = reader.ReadToEnd();
}
}
var newContent = content.Replace(">", ">");
using (var target = new MemoryStream())
using (var writer = new StreamWriter(target))
{
writer.Write(newContent);
target.Seek(0, SeekOrigin.Begin);
blob.UploadFromStream(target);
}
Console.WriteLine("Press any key to continue!");
Console.ReadKey();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment