我正在尝试为服务器中的路径创建linkbutton,但它不起作用 此外,我尝试使用LinkButton,但它仍然没有工作。
C#:
string path = "U:\\HR\\resume\\System\\" + Department + "\\" + ID + extFile;
if (File.Exists(path))
{
HyperLinkDownload.ID = ID.ToString();
lbResumeExist.Text = "File Exists";
HyperLinkDownload.Text = "download";
HyperLinkDownload.NavigateUrl = ID + ext.ToString();
LinkButton1.Text = "download";
LinkButton1.PostBackUrl= path;
}
else
{
HyperLinkDownload.Visible = false;
lbResumeExist.Visible = false;
LinkButton1.Visible = false;
}
ASP:
<asp:HyperLink ID="HyperLinkDownload" runat="server"></asp:HyperLink>
<br /><br />
<asp:LinkButton ID="LinkButton1" runat="server"></asp:LinkButton>
<br /><br />
错误消息:
无法找到资源。
描述:HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。
请求的网址:/51.doc
如果我将字符串HyperLinkDownload更改为:“HyperLinkDownload.NavigateUrl = path;” 超链接没有响应点击,当我点击检查元素后,我收到此错误信息
HTTP错误400 - 错误请求。
版本信息:ASP.NET Development Server 10.0.0.0
答案 0 :(得分:1)
使用Server.MapPath(“您的目标文件”)而不是手动编写路径@“U:/ HR / Resume .... bla..bla ...”..
如果下载仍无法正常运行,请尝试使用此代码。
// send the PDF document as a response to the browser for download
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ContentType = "application/pdf";
if (!displayOnBrowser)
{ response.AddHeader("Content-Disposition", String.Format("attachment; filename=GettingStarted.pdf; size={0}", pdfBytes.Length.ToString()));
}
else
{ response.AddHeader("Content-Disposition", String.Format("inline; filename=GettingStarted.pdf; size={0}", pdfBytes.Length.ToString()));
}
response.BinaryWrite(pdfBytes);
// Note: it is important to end the response, otherwise the ASP.NET
// web page will render its content to PDF document stream
response.End();