0
リンクボタン(ダウンロード)をクリックしてアップロードしたファイルをダウンロードし、アップロードされたファイルをダウンロードする別のボタンをクリックすると、コードが表示されます。他のボタンをクリックしたときにファイルをダウンロードする
lblFile.Text = Issue.FileName;
if (lblFile.Text != "")
{
trAttachedFile.Visible = true;
lbtnDownload.PostBackUrl = "~/Download.aspx?file=" + lblFile.Text;
}
else
{
trAttachedFile.Visible = false;
}
そして、ここでは
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["file"]))
{
DownloadID = Request.QueryString["file"];
if (StartDownload() == true)
{
lblMessage.Text = "Your download should start shortly";
}
else
{
lblMessage.Text = "Download File does not exist";
}
}
private bool StartDownload()
{
if (DownloadID != "")
{
string downloadPath = WebConfigurationManager.AppSettings["SubPic"].ToString() + DownloadID;
FileInfo downloadFile = new FileInfo(downloadPath);
if (downloadFile.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadFile.Name);
Response.AddHeader("Content-Length", downloadFile.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(downloadFile.FullName);
Response.End();
return true;
}
}
return false;
}
背後Download.aspxコードだと、ここであなたはボタンのPostBackUrlプロパティを使用する場合、それはフォームのPostBackUrl
を変更するためのLinkButton
<tr runat="server" id="trAttachedFile">
<td>
<asp:Label runat="server" Text="File Attachment:" />
</td>
<td colspan="2">
<asp:Label runat="server" ID="lblFile" />
<asp:LinkButton runat="server" Text="Download" ID="lbtnDownload" CssClass="lbtnDownload" />
</td>
<td> </td>
</tr>
ありがとうございます。どうもありがとうございます –