Reputation: 530
I have a .NET project, where I have a direct link to download .mp4 to users hard drive. It works fine in chrome, but in IE, it saves it as a .data file. Does anyone know how I can fix this?
In my .aspx page I use this link:
<asp:hyperlink Visible="false" id="dlVideo" Font-Size="8pt" NavigateUrl='<%# Eval("VideoName", "~/Workshops/Refology/Get.aspx?FileName={0}&OrigName=" + Eval("FirstName") + "&CamperName=" + Eval("lastname") + "&Topic=" + Eval("Topic"))%>' runat="server" Text='<%# IIf(Eval("VideoName") Is DBNull.Value, "", "Video")%>'></asp:hyperlink>
And in the Get.aspx.cs page is this:
protected void Page_Load(object sender, EventArgs e)
{
string videoName = Request.QueryString["FileName"];
string OriginalName = Request.QueryString["OrigName"];
string PersName = Request.QueryString["CamperName"];
string Topic = Request.QueryString["Topic"];
string FinalName = PersName + "-" + OriginalName + "-" + Topic;
Response.Clear();
Response.ContentType = "video/mp4";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FinalName);
Response.TransmitFile(Server.MapPath("~/contents/published/" + videoName));
Response.Flush();
Response.End();
}
Upvotes: 1
Views: 358
Reputation: 101614
Taking a guess, but chances are it's because you're exempting the extension from your filename in the Content-Disposition
header. Also, if your FinalName has spaces in it, your header is going to be messed up; you should probably escape it. e.g.
/* ... */
var contentDisposition = new System.Net.Mime.ContentDisposition("attachment")
{
FileName = FinalName + ".mp4"
}:
// Properly encode header using ContentDisposition class.
Response.AddHeader("Content-Disposition", contentDisposition.ToString());
The ContentDisposition
class can build the header for you encoding it as necessary.
Upvotes: 1