2
I am downloading files with ASP.NET Web Forms at a Linkbutton click event as follows:
var file = new FileInfo(filePath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name));
Response.AddHeader("Content-Length", file.Length.ToString(CultureInfo.InvariantCulture));
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
The code works, but when the file is a .txt
the same, in addition to its original content, comes with all the HTML of the current page. Someone knows how to solve this?
This is ASP.NET MVC, Webforms, Webapi... could post more details of the context in which you are running the code you specified?
– Miguel Angelo
@I edited the question.
– Caique C.