1

So basically the html looks like this

<a href='test.pdf' Download>download test</a>

But I need this to be made in C# what I have so far is

HtmlAnchor link = new HtmlAnchor();
link.Href = "test.pdf";
link.innerText = "download test";

How do I put that "Download" part in so that when you click the link it would actually download the file and not link to it?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
5tar-Kaster
  • 910
  • 2
  • 12
  • 30

2 Answers2

1

You need to use InnerHtml instead of InnerText along with <b> for bold

link.InnerHtml = @"<b>download test</b>";

Edit based on OP Edit,

You will need to use Response.WriteFile on linkButton click event, you probably look for something being asked in this post.

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();
Community
  • 1
  • 1
Adil
  • 146,340
  • 25
  • 209
  • 204
1

Try this one: Place in your html page, in C#, Write: litdoc.Text += "" + "download test" + ""; In handler: mention code to download pdf file, just like :

    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();

    }

where path is the location from where you download pdf file.

Priya Gund
  • 156
  • 5