Created
November 24, 2012 16:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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