To jest mój kod i próbuję od godziny pobrać plik docx. ale bez powodzenia. Gdzie mogę być w tyle, potrzebuję delikatnej podpowiedzi.Nie można pobrać pliku docx za pomocą 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();
}
i daje Powrót typ zawartości, typ zawartości dla pliku docx:
"application/ms-word"
gdzie jeśli sTempPath + sCreateFileName jest cała ścieżka pliku.
Aktualizacja: Próbowałem Rodzaj treści:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
To nie działa.
jaki błąd masz? –
spróbuj z typem zawartości jako 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' – Damith
Nie ma błędu, ale plik nie jest pobierany. –