I have this download function :
protected void ExportData(string fileName, string fileType, string path)
{
System.IO.StreamReader sr = new System.IO.StreamReader(path);
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
Response.Charset = "";
Response.ContentType = fileType;
Response.Output.Write(sr.ReadToEnd());
Response.Flush();
Response.End();
}
I use it :
ExportData("infoMandat_" + g.NO_MANDAT + ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", g.URL_infoMandat);
But the file is always empty OR corrupted...
Probably because i'm reading it with a plain StreamReader
The solution proposed in the answer is the function .Transmit()
, question marked as duplicate is absolutely not the solution to THIS question.