0

I had a quick requirement from my client that he want to store some files in a Folder in web server (we have a temp folder which has rights to allow Everybody).

He want to place the file in that directly and give the link e.g. http://www.abcd.com/temp/somefile.rdl to his customer to directly download the file.

Is there any readymade aspx page available so that I can just use that page set path of folder and it should work this way.

If not can I quickly create it using only aspx page.

I almost did it with the following code in aspx

<%
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + Server.MapPath("~/TempReport/"+Request.QueryString["file"]) + "\"");
Response.ContentType = "Application/cab";
Response.TransmitFile(Server.MapPath("~/TempReport/"+Request.QueryString["file"]));
Response.End();
%>

The only problem is that I can only download cab type of file due to following line:

Response.ContentType = "Application/cab";

I want any kind of file to be downloaded.

Imran Rizvi
  • 7,331
  • 11
  • 57
  • 101

1 Answers1

1

Check this post for answer, to get MIME type which should be set for your content Type

Using .NET, how can you find the mime type of a file based on the file signature not the extension

Or you can just put, which should work fine for downloading binary file. Response.ContentType = "application/octet-stream";

        Page.Response.ContentType = "application/octet-stream"
        Page.Response.AddHeader("Content-Disposition", "attachment; filename=""" & strFilename & """")
        Page.Response.OutputStream.Write(objAttachment.Data, 0, objAttachment.Data.Length)
Community
  • 1
  • 1
Guru Kara
  • 6,272
  • 3
  • 39
  • 50