code est ci-dessous où AJAX envoyer une requête POSTErreur lors du téléchargement du fichier en utilisant ASP.net C#
Fondamentalement, je veux télécharger un fichier depuis un emplacement (chemin complet) à la page charge
Mais quand je cette page est appelé pas d'erreur est lancé la page obtiennent l'appel avec succès Même j'obtiens file.Exist = vrai, la réponse est créée mais sur le navigateur rien ne se produit Je m'attends à la boîte de dialogue de téléchargement de fichier. sur la poursuite de débogage j'ai trouvé exception objet Response têtes 'Response.Headers' = a lancé une exception de type 'System.PlatformNotSupportedException' Cette opération nécessite IIS intégré mode pipeline
Je cours cette page web mon localhost (serveur de développement de studio visuel). .net4 et VS2010
Sur la page Code charge:
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();
}
}
fonction
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";
}
}
jetez un oeil à ce qui suit http://stackoverflow.com/questions/1940100/cant-download-word-document-throwing-exception – user1666620
@ user1666620 J'utilise Visual Studio enveloppement serveur –
et qui utilise iis express pour fonctionner le site lorsque vous le lancez à partir de VS. – user1666620