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

harlem98

Member
Joined
Nov 4, 2021
Messages
12
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:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,029
Location
Chesapeake, VA
Programming Experience
10+
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.
 

harlem98

Member
Joined
Nov 4, 2021
Messages
12
Programming Experience
Beginner
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
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
4,029
Location
Chesapeake, VA
Programming Experience
10+

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,266
Location
Norway
Programming Experience
10+
"attachment; filenameT=" in Content-Disposition is probably copy-paste error, should be "attachment; filename="
 
Solution
Top Bottom