Questo è il mio codice e sto cercando da ore di scaricare il file docx. ma nessun successo. Dove posso essere in ritardo, ho bisogno di un leggero suggerimento.Impossibile scaricare il file docx utilizzando C#
if (File.Exists(sTempPath + sCreateFileName))
{
FileInfo file =new FileInfo(sTempPath + sCreateFileName);
Response.ClearContent();
// LINE1: Add the file name and attachment, which will force the open/cancel/save dialog to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", file.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(file.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(sTempPath + sCreateFileName);
// End the response
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
e ritorno tipo di contenuto dà, tipo di contenuto per il file docx:
"application/ms-word"
dove se sTempPath + sCreateFileName è l'intero percorso del file.
Aggiornamento: ho provato tipo di contenuto:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
Questo non funziona.
quale errore hai? –
prova con il tipo di contenuto come 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' – Damith
Non c'è nessun errore ma il file non viene scaricato. –