1

我正在尝试创建链接按钮到服务器中的路径,但它不起作用。
此外,我尝试使用 LinkBut​​ton 进行操作,但仍然无法正常工作。

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。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。

请求的网址:/51.doc

如果我将字符串 HyperLinkDownload 更改为:“HyperLinkDownload.NavigateUrl =path;” 超链接未响应单击,当我在检查元素后单击时收到此错误消息

HTTP 错误 400 - 错误请求。

版本信息:ASP.NET 开发服务器 10.0.0.0

4

1 回答 1

1

使用 Server.MapPath("your destination file") 而不是手动写入路径 @"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();
于 2013-07-07T02:11:32.753 回答