How to download a file by the browser from a directory in my project?
I tried the following, but nothing happens:
string path = "C:\test.txt";
var file = new FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "text/plain";
Response.Flush();
Response.TransmitFile(file.FullName);
Response.End();
}
I debugged and the values are all correct, but do not drop anything in the browser, how do I?
<system.web>
<!-- Autenticação-->
<authentication mode="Forms">
<forms name="login" loginUrl="login.aspx" protection="All" timeout="1" defaultUrl="pagina.aspx" requireSSL="false"/>
</authentication>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
<httpRuntime maxRequestLength="50000" />
<pages controlRenderingCompatibilityVersion="4.0"/>