First Create your container in Azure and get your AccountName and Access Key to your ur blob Storage.
Follow this link : http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs-20/
Than in your visual studio create a class file and follow code given below :
public class BlobStorageService
{
public CloudBlobContainer GetCloudBlobContainer()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["BlobSetting"]);
CloudBlobClient blobclient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobcontainer = blobclient.GetContainerReference("mycontainer");
if (blobcontainer.CreateIfNotExists())
{
blobcontainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
return blobcontainer;
}
public string GetReadData(string filename)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["BlobSetting"]);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// Retrieve reference to a blob named "myblob.csv"
CloudBlockBlob blockBlob2 = container.GetBlockBlobReference(filename);
string text;
using (var memoryStream = new MemoryStream())
{
blockBlob2.DownloadToStream(memoryStream);
text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
}
return text;
}
}
Controller :
[HttpPost]
public ActionResult UploadDevicesToRegister11(HttpPostedFileBase userDetailCsvfile)
{
BlobStorageService df = new BlobStorageService();
if (userDetailCsvfile.ContentLength > 0)
{
//To upload file on Blob
CloudBlobContainer blobContainer = df.GetCloudBlobContainer();
CloudBlockBlob blob = blobContainer.GetBlockBlobReference(userDetailCsvfile.FileName);
blob.UploadFromStream(userDetailCsvfile.InputStream);
//To read File from Blob
blobContainerRead = df.GetReadData(userDetailCsvfile.FileName);
}
return View();
}
Hope this Helps.