【发布时间】:2015-07-06 18:49:20
【问题描述】:
早期的开发人员使用标签放置此代码,并在运行时将其转换为超链接。
<asp:Label ID="lbl_Attachment" runat="server">
</asp:Label>
lbl_Attachment.Text = "<a href='../Uploads/" +
ds_row["Attachment"].ToString() + "'>" +
ds_row["Attachment"].ToString() + "</a>";
但这不起作用。所以我将代码更改为以下,以在新的浏览器选项卡中打开任何文件(图像/pdf/word),错误仍然存在:
hyperlinkAppDoc.NavigateUrl =
ResolveUrl("../Uploads/" +
ds_row["Attachment"].ToString());
hyperlinkAppDoc.Target = "_blank";
我可以做些什么来解决这个问题? MIME 类型在 IIS 中可用。
更新:
我正在尝试一种不同的方法。但是Server.MapPath 指向本地驱动器而不是 wwwroot。如何将路径指向 wwwroot 文件夹?
string pdfPath = Server.MapPath("~/SomeFile.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(pdfPath);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
【问题讨论】:
标签: asp.net file c#-4.0 hyperlink