0

我需要一些帮助,我有一个位于 ftp 位置的 pdf 文件。

我想要做的是单击按钮,我想检索 pdf 文件并将其显示在新选项卡上。

请协助完成此任务。

提前致谢。

4

2 回答 2

2

一种方法是发出 Web 请求以下载文件,然后将下载流传递给 ASP.NET 响应流。我还没有编译或执行这段代码,但它可能看起来像这样:

WebRequest request = HttpWebRequest.Create("ftp://ftp.yoursite.com/yourfile.pdf");
request.Credentials = new NetworkCredential("ftpuser","ftppassword");

// Get the response
WebResponse response = request.GetResponse();
StreamReader responseStream = new StreamReader(response.GetResponseStream());

// Send the response directly to output
Response.ContentEncoding = responseStream.CurrentEncoding;
Response.ContentType = "application/pdf";
Response.Write(responseStream.ReadToEnd());
Response.End();
于 2012-08-04T15:04:29.027 回答
1

只需使用 HTML 锚标记(“a”标记)。在href属性中放置 PDF 文件的 FTP 地址(例如ftp://example.com/file.pdf)。要在新窗口中打开,您还应该使用 value 指定target属性"_blank"

例子:

<a href='ftp://example.com/file.pdf' target='_blank'>Click here to open the PDF file</a>

于 2012-08-04T15:04:02.040 回答