I have try to code for user to download the .dat file by using Response.Redirect. However, it always show me this error.
The page you are requesting cannot be served because of the extension
configuration. If the page is a script, add a handler. If the file should be
downloaded, add a MIME map.
My sample code for Response.redirect
Response.Redirect(filepath, false);
I don't no what wrong with it. Plus,I can download .xlsx file by using this code.
Thanks for helping me.
This is the updated code that have no response to download.
EDITED CODE
string fpath = Server.MapPath("data") + "\\" + filename + ".dat";
if (File.Exists(fpath))
{
File.Delete(fpath);
}
StreamWriter swExtLogFile = new StreamWriter(fpath, true);
try
{
int i;
foreach (DataRow row in tbl.Rows)
{
object[] array = row.ItemArray;
for (i = 0; i < array.Length - 1; i++)
{
swExtLogFile.Write(array[i].ToString());
}
swExtLogFile.WriteLine(array[i].ToString());
}
swExtLogFile.Close();
swExtLogFile.Dispose();
FileInfo fInfo = new FileInfo(fpath);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length", fInfo.Length.ToString());
Response.AppendHeader("content-disposition",
string.Format("attachment;filename={0}", fInfo.Name));
Response.Flush();
Response.TransmitFile(fInfo.FullName);
HttpContext.Current.ApplicationInstance.CompleteRequest();