これは私のコードであり、docxファイルをダウンロードするために何時間も努力しています。成功はない。 私が遅れているかもしれないところでは、少しのヒントが必要です。C#を使用してdocxファイルをダウンロードすることができません
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();
}
と戻り、コンテンツタイプ、DOCXファイルのコンテンツタイプできます:sTempPath + sCreateFileNameは、ファイルのパス全体である場合
"application/ms-word"
。
更新: 私は、コンテンツタイプを試してみました:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
これは動作しません。
あなたはどんなエラーがありますか? –
コンテンツタイプを 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'として試してください – Damith
ファイルはダウンロードされていませんが、エラーはありません。 –