pdfファイルのダウンロードに問題があります。他のファイルはダウンロードされます。 コード:uはC#でPDFファイルをダウンロードするコード
答えて
チェックこの方法を知っていれば
WebClient client = new WebClient();
client.DownloadFile(remoteFilename, localFilename);
のplsは私を助けて、希望
public static void DownloadFile(HttpResponse response,string fileRelativePath)
{
try
{
string contentType = "";
//Get the physical path to the file.
string FilePath = HttpContext.Current.Server.MapPath(fileRelativePath);
string fileExt = Path.GetExtension(fileRelativePath).Split('.')[1].ToLower();
if (fileExt == "pdf")
{
//Set the appropriate ContentType.
contentType = "Application/pdf";
}
//Set the appropriate ContentType.
response.ContentType = contentType;
response.AppendHeader("content-disposition", "attachment; filename=" + (new FileInfo(fileRelativePath)).Name);
//Write the file directly to the HTTP content output stream.
response.WriteFile(FilePath);
response.End();
}
catch
{
//To Do
}
}
あなたはcontentType = "Application/pdf"を設定する必要があります。ダウンロードしたファイルが正しいことを確認するPDFファイル –
ありがとうMahmoud私はこれを試しましたが、次のエラーが表示されます:型または名前空間の名前 'HttpResponse'が見つかりませんでした(使用するディレクティブまたはアセンブリ参照がありません) –
あなたはWebアプリケーションやデスクトップアプリケーションで作業していますか? –
@Syed Mudhasir役立ちます: そのちょうどライン:)
client.DownloadFileAsync(new Uri(remoteFilename, UriKind.Absolute), localFilename);
を
pdfファイルをダウンロードします。 :)
次のコードサンプルをダウンロードしてください.pdfファイルをダウンロードしてください。
Response.ContentType = "Application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=Test_PDF.pdf");
Response.TransmitFile(Server.MapPath("~/Files/Test_PDF.pdf"));
Response.End();
これが私の仕事:
string strURL = @"http://192.168.1.xxx/" + sDocumento;
WebClient req = new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.AddHeader("Content-Disposition", "attachment;filename=\"" + sDocumento + "\"");
byte[] data = req.DownloadData(strURL);
response.BinaryWrite(data);
response.End();
- 1. pdfファイルのダウンロード
- 2. AFNetworking 2.0でPDFファイルをダウンロード
- 3. ScrapyでPDFファイルをダウンロードする
- 4. 最新のpdfをダウンロードするコード
- 5. C#でファイルをダウンロードする
- 6. PDFファイルをダウンロードするのではなく、ブラウザでPDFファイルを開く
- 7. wikipediaからpdfファイルをダウンロード
- 8. APIからPDFファイルをダウンロード
- 9. URLからPDFファイルをダウンロード
- 10. Android WebviewダウンロードマネージャーPDFファイルをダウンロードする
- 11. PDFファイルをダウンロードするAJAX POST - ASP.NET
- 12. UWPでPDFとWordファイルをダウンロード
- 13. ダウンロードからPDFファイルをダウンロードDreamfactory in PHPでリンクしますか?
- 14. wgetでpdfファイルをダウンロードする。 (ファイル拡張後の文字)
- 15. ABLコードからPDFファイルをダウンロードする際にエラーが発生しました
- 16. ウェブサイトからPDFファイルをダウンロードし、ダウンロード後にファイル名を変更する
- 17. urllib2でPythonをダウンロードするとPDFファイルが破損する
- 18. C#でPDFファイルを編集する
- 19. パスワードでPDFファイルを保護するC#
- 20. pythonでhttpsでpdfファイルをダウンロードするには
- 21. PDFファイルが2回ダウンロードされる - IE8
- 22. FORM POSTリクエストでファイルをダウンロードするC#
- 23. asp.netでファイルをダウンロードするC#
- 24. C#でFTPからファイルをダウンロードする
- 25. 目的C:プログレスバーでファイルをダウンロードする
- 26. PHPを使用してpdfファイルをダウンロード
- 27. C#コードをダウンロードするinspect要素
- 28. PHPとローカルサーバーからpdfファイルをダウンロード
- 29. このpdfファイルをダウンロードしたい
- 30. HTMLを使用したPdfファイルのダウンロード
問題は何ですか? –
私の問題は、上記のコードを使ってpdfファイルをダウンロードしてpdfドキュメントとして保存した後です。私はそれを開くしようとすると、ドキュメントの修復エラーを示しています。 –
私は...あなたを助けるでしょう」リンクの下にこれを期待し http://stackoverflow.com/questions/10829168/can-we-use-response-flush-instead-of-response-end/17038408 #17038408 – Viishnuu