Label lblfilename = (Label)row.FindControl("lblGrid_filename"); Label lblfilesize = (Label)row.FindControl("lblGrid_hidfileSize"); string downloadfile = lblfilename.Text.ToString(); // DownloadFileFromBlob(downloadfile, CONTAINER, ACCOUNTKEY); AccountFileTransfer = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=" + ACCOUNTNAME + ";AccountKey=" + ACCOUNTKEY); if (AccountFileTransfer != null) { BlobClientFileTransfer = AccountFileTransfer.CreateCloudBlobClient(); ContainerFileTransfer = BlobClientFileTransfer.GetContainerReference(CONTAINER); ContainerFileTransfer.CreateIfNotExist(); BlobRequestOptions options = new BlobRequestOptions(); options.Timeout = new TimeSpan(0, 180, 0); } var data = Regex.Match(lblfilesize.Text.ToString(), @"\d+").Value; int value32; Int64 value64; var blobSize = 0L; var blockSize = 0L; var offset = 0L; if (int.TryParse(data, out value32)) { blobSize = Convert.ToInt32(lblfilesize.Text.ToString()); } else if (Int64.TryParse(data, out value64)) { blobSize = Convert.ToInt64(lblfilesize.Text.ToString()); } var blob = ContainerFileTransfer.GetBlockBlobReference(downloadfile); var sasUrl = blob.Uri.AbsoluteUri; CloudBlockBlob blockBlob = new CloudBlockBlob(sasUrl); //blobSize = Convert.ToInt32(lblfilesize.Text.ToString()); blockSize = 5 * 1024 * 1024; Response.Clear(); Response.ContentType = "APPLICATION/OCTET-STREAM"; System.String disHeader = "Attachment; Filename=\"" + blockBlob.Name + "\""; //Response.AppendHeader("Content-Disposition", disHeader); for (offset = 0; offset < blobSize; offset += blockSize) { using (var blobStream = blockBlob.OpenRead()) { if ((offset + blockSize) > blobSize) { blockSize = (blobSize - offset); } byte[] buffer = new byte[blockSize]; blobStream.Read(buffer, 0, buffer.Length); Response.BinaryWrite(buffer); Response.Flush(); } } Response.End();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)