C# 使用C将下载添加到锚定标记#
基本上html是这样的C# 使用C将下载添加到锚定标记#,c#,asp.net,hyperlink,C#,Asp.net,Hyperlink,基本上html是这样的 <a href='test.pdf' Download>download test</a> 我如何将“下载”部分放入,以便当您单击链接时,它实际上会下载文件而不是链接到它 感谢高级版。您需要使用InnerHtml,而不是InnerText,同时使用进行粗体显示 link.InnerHtml = @"<b>download test</b>"; 试试这个:在你的html页面中,用C#写下:litdoc.Text++=“+”
<a href='test.pdf' Download>download test</a>
我如何将“下载”部分放入,以便当您单击链接时,它实际上会下载文件而不是链接到它
感谢高级版。您需要使用
InnerHtml
,而不是InnerText
,同时使用
进行粗体显示
link.InnerHtml = @"<b>download test</b>";
试试这个:在你的html页面中,用C#写下:litdoc.Text++=“+”下载测试“+”;在handler中:提及下载pdf文件的代码,如下所示:
string file = "";
file = context.Request.QueryString["file"];
if (file != "")
{
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition", "attachment;filename=" + Path.GetFileName(file));
context.Response.WriteFile(file);
context.Response.End();
}
其中路径是下载pdf文件的位置 这甚至不是我问的问题。。。但是我编辑了这个问题,所以现在应该更清楚了,我希望。是的,很抱歉我的问题含糊不清。但无论如何,将文件写入网站将如何使其下载?我不明白它是怎么工作的?我不知道它是怎么工作的,但我很高兴:)谢谢你把这说清楚。在您的示例中,PDF文件在浏览器中打开,而不是显示“保存文件”对话框?这意味着显示要保存或打开的对话框。在Html代码中,它会显示该框,但在C#中,它不会显示.link.Attributes.Add(“下载”、“下载”);当你使用C#
HtmlAnchor
时,你能不能发布你生成的html代码(检查网页浏览器页面)?生成的代码正是-->现在我只需要在。。。
FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ContentType = "Application/msword";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.WriteFile(fileInfo.FullName);
Response.End();
string file = "";
file = context.Request.QueryString["file"];
if (file != "")
{
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition", "attachment;filename=" + Path.GetFileName(file));
context.Response.WriteFile(file);
context.Response.End();
}