Skip to content

Instantly share code, notes, and snippets.

@Tapanila
Created August 6, 2012 05:27
Show Gist options
  • Save Tapanila/3271026 to your computer and use it in GitHub Desktop.
Save Tapanila/3271026 to your computer and use it in GitHub Desktop.
using System.IO;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
namespace SimpleWCFService
{
public class Service1 : IService1
{
string storageConnectionString =
"DefaultEndpointsProtocol=https;AccountName={Storage Account Name};" +
"AccountKey={PRIMARYKEY}";
public bool SaveText(string content, string blobName, string containerName)
{
CloudStorageAccount storageAccount =
CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container
CloudBlobContainer container =
blobClient.GetContainerReference(containerName);
// Create the container if it doesn't already exist
container.CreateIfNotExist();
// Retrieve reference to a blob named "myblob"
CloudBlob blob = container.GetBlobReference(blobName);
// Create or overwrite the blob with content
blob.UploadText(content);
return true;
}
public string RetrieveText(string containerName, string blobName)
{
CloudStorageAccount storageAccount =
CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container
CloudBlobContainer container =
blobClient.GetContainerReference(containerName);
// Create the container if it doesn't already exist
container.CreateIfNotExist();
// Retrieve reference to a blob named "myblob"
CloudBlob blob = container.GetBlobReference(blobName);
StreamReader reader = new StreamReader(blob.OpenRead());
return reader.ReadToEnd();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment