質問
私はサーバーで完全に開いている単語文書を持っていますが、ボタンを使ってダウンロードすると、私のウェブサイトのイベントをクリックしますそれは起こります。 以下のコードを使用してボタンをクリックしてドキュメントのダウンロードを行います。 この問題を解決するのに役立ちます。 .NET Framework 3.5
を使用しています Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=StandardLetter" + _responseId.ToString() + ".doc");
Response.ContentType = "application/octet-stream";
Response.TransmitFile (Server.MapPath("~/document/letter/StandardLetter" + _responseId.ToString() + ".doc"));
. 解決
OKここで私が使用するコードは、それはVBですが簡単に変換されます。)
Response.ContentType = "application/pdf"
Dim byteArray As Byte() = File.ReadAllBytes(MergedFile)
Response.AddHeader("Content-Disposition", "attachment;filename=""" & ShortFilename & """")
Response.AddHeader("Content-Length", byteArray.Length)
Response.BinaryWrite(byteArray)
Response.Flush()
Response.End()
.
PDFでは、.ContentTypeを変更することによって機能します。頑張って!
私はMergedFileというPDF文書を取り出して、それをbyte()に変換する、私はそれをユーザーによって入力できる 'shortname'を与えます。Content-Lengthは非常に重要です..
他のヒント
代わりに試してみてください:
Response.ContentType ="application/msword";
.
私は言葉を使わないがExcelのために使います:
Response.ContentType = "application/x-msexcel"
. 所属していません StackOverflow