Created
August 6, 2012 05:27
-
-
Save Tapanila/3271026 to your computer and use it in GitHub Desktop.
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
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