Below is code where AJAX send POST request
Basically I want to download a file from some location(full path) on page load
But when I this page is called no error is thrown page get call succesfully Even I get file.Exist=true , Response is created but on browser nothing happens I expecting file download dialog. on further debugging I found exception in Response object Headers = 'Response.Headers' threw an exception of type 'System.PlatformNotSupportedException' This operation requires IIS integrated pipeline mode
I am running this web page in my localhost(visual studio development server). .net4 and VS2010
On Page Load Code:
protected void Page_Load(object sender, EventArgs e)
{
string path = Request.Form["path"];
// string reportName=path.Substring( path.LastIndexOf("\\") ,path.Length);
DAL.IO_helper i = new DAL.IO_helper();
string fullpath = i.GetReportsPath() + path;
FileInfo report = new FileInfo(fullpath);
if (report.Exists)
{
Response.ClearContent();
Response.ClearHeaders();
// Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + report.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", report.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(report.Extension.ToLower());
// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(report.FullName);
//Transmit file
Response.Flush();
// End the response
Response.End();
}
else
{
Response.ClearContent();
// End the response
Response.End();
}
}
function
private string ReturnExtension(string fileExtension)
{
switch (fileExtension)
{
case ".txt":
return "text/plain";
case ".dat":
return "text/plain";
case ".doc":
return "application/ms-word";
case ".docx":
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
case ".zip":
return "application/zip";
case ".xls":
return "application/vnd.ms-excel";
case ".xlsx":
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
case ".csv":
return "application/vnd.ms-excel";
case ".pdf":
return "application/pdf";
case ".xml":
return "application/xml";
case ".sdxl":
return "application/xml";
default:
return "application/octet-stream";
}
}