1

したがって、基本的にhtmlは次のようになります

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

しかし、これをC#で作成する必要があります。これまでのところ

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

リンクをクリックしたときに実際にファイルをダウンロードし、リンクしないように、その「ダウンロード」部分を配置するにはどうすればよいですか

ありがとうございます。

4

2 に答える 2

1

これを試してみてください: HTML ページに C# で配置して、次のように記述します: litdoc.Text += "" + "download test" + ""; ハンドラーで:次のように、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();

    }

path は、pdf ファイルをダウンロードする場所です。

于 2013-10-29T06:56:35.797 に答える
1

太字には withのInnerHtml代わりに使用する必要がありますInnerText<b>

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

OP Editを元に編集し、

linkBut​​ton クリック イベントで Response.WriteFile を使用する必要があります。おそらく、この投稿で質問されていることを探します。

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();
于 2013-10-29T06:25:18.790 に答える