0

I'm making project which includes downloading files from cloud(Azure) storage. I want to open save as dialog box but not getting it . I used following code.

enter code here // Retrieve reference to a blob named "myblob".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob1");
        string FileName = "a3.jpg";
        string Filename = FileName.Substring(0, FileName.LastIndexOf("."));``
        Response.AppendHeader("Content-Disposition", "attachment; filename=" FileName);
        Response.TransmitFile(Server.MapPath("~/blockBlob/myblob1/" + Filename));
        Response.End();

        /* to download file from cloud

using(var fileStream =System.IO.File.OpenWrite(@"C:\Users\prak\Pictures\ppp.JPG")) { blockBlob.DownloadToStream(fileStream); Response.Write("
"); Response.Write("Succefully downloaded!"); }*/

please help... thanks in advance

user81239
  • 1
  • 2

1 Answers1

0

You will need to redirect your form to an ashx handler that writes the file content directly into the output stream. This is not specific to Azure, although if the file is being accessed from a blob it may need to be moved temporarily to the web server so you can reference the local path in the "attachment;filename".

Response.Clear();
Response.ContentType = "image/jpeg";
Response.AddHeader( "Content-Disposition", "attachment;filename=\"myfile.jpg\"" );
// write file data to output stream here
Response.End();

Another method is to use HttpWebRequest as described in the following post:

Download/Stream file from URL - asp.net

Community
  • 1
  • 1
QFDev
  • 8,668
  • 14
  • 58
  • 85
  • sorry....it isn't working.....actually an empty file gets transferred.... I used following code : Response.Clear(); Response.ContentType = p; Response.AddHeader("Content-Disposition", "attachment; filename=" +p);*/ // write file data to output stream here using (var fileStream = System.IO.File.OpenWrite( @"C:\Users\public\desktop\"+p)) { blockBlob.DownloadToStream(fileStream);} Response.End(); – user81239 Apr 18 '13 at 12:55