Resolved File downloads as "Defaulf.aspx" instead of normal content

harlem98

Active member
Joined
Nov 4, 2021
Messages
27
Programming Experience
Beginner
Hello community!

I am downloading a file, which when i download it, it downloads with File name and type "Default.Aspx" instead of the expected file content.
Any ideas about the issue?

Export method used on a normal link button:
protected void ExportFile_Click(object sender, EventArgs e)
        {

            var IDTemplate = (((LinkButton)sender).CommandArgument); //ID of the file in DB
            var model = templatebll.GetFile(); //BLL method
            if (model.FileContentT != null)
            {
                Response.Clear();
                Response.ClearHeaders();
                Response.AddHeader("Content-Type", "Application/octet-stream");
                Response.AddHeader("Content-Length", model.FileContentT.Length.ToString());
                Response.AddHeader("Content-Disposition", "attachment; filenameT=" + model.FileNameT + "." + model.FileTipoT);
                Response.BinaryWrite(model.FileContentT);
                Response.Flush();
                Response.End(); //Response.Close();
            }
        }
 
Last edited:
Like I told you in your other thread, BinaryWrite() will not magically treat the string that you pass it as a file that it needs to open and then send the file data down to the user. BinaryWrite() will take the string literally as a set of bytes and send that to the user.
 
Like I told you in your other thread, BinaryWrite() will not magically treat the string that you pass it as a file that it needs to open and then send the file data down to the user. BinaryWrite() will take the string literally as a set of bytes and send that to the user.
Now it passes the file, as the page form name (Default.aspx).. Don't have any reference to that
 
"attachment; filenameT=" in Content-Disposition is probably copy-paste error, should be "attachment; filename="
 
Solution

Latest posts

Back
Top Bottom