In this post I will show you to download a file from Azure BLOB.
Set the Connection String as below,
Function to download and save file is as below,
public void DownloadFileFromBlob(string fileName, string containerName,string storageConnectionString) { account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(storageConnectionString)); blobClient = account.CreateCloudBlobClient(); container = blobClient.GetContainerReference(containerName); blob = container.GetBlobReference(fileName); MemoryStream memStream = new MemoryStream(); blob.DownloadToStream(memStream); Response.ContentType = blob.Properties.ContentType; Response.AddHeader("Content-Disposition", "Attachment; filename=" + fileName.ToString()); Response.AddHeader("Content-Length", blob.Properties.Length.ToString()); Response.BinaryWrite(memStream.ToArray()); }
you need to pass
- Connection string to BLOB storage
- Public Container name
- BLOB name or file name
Thanks for reading. I hope this post was useful
Leave a Reply