文件没有下载 [英] file doesnt download
本文介绍了文件没有下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我要下载pdf文件。这是由user.bt选择的问题是只有我放置所有文件的文件夹的第一个文件是dwonloaded ..
而不是其他..
i觉得有什么东西都被我迷了..
bt能够找到..
plz帮帮我。
我的代码如下:
here i have to download pdf file. which is selected by the user.bt the problem is that only the first file of the folder at where i placed the all file is dwonloaded..
and not others..
i think anything is missied by me..
bt enable to find..
plz help me out.
my code is given below.
DirectoryInfo directory = new DirectoryInfo(Server.MapPath("~/Booksimg/pdf/"));
foreach (FileInfo file in directory.GetFiles())
{
Response.Redirect("Download.aspx?snm=" + file.Name);
}
下载后代码.aspx
code behind of download .aspx
string fileName = Request.QueryString["snm"].ToString();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.TransmitFile(Server.MapPath("~/Booksimg/pdf/" + fileName));
Response.End();
推荐答案
我只是猜测你希望用户能够点击在链接上?
因此将其输出为链接而不是Response.Redirect:这是我用来将类似链接放入HTML表格的文本:
I''m just guessing that you want the user to be able to click on a link?
So output it as a link instead of Response.Redirect: This is the text I use to put similar links into an HTML table:
/// <summary>
/// Add a download file's information to a table row.
/// </summary>
/// <param name="dl"></param>
/// <returns></returns>
private static HtmlTableRow AddDownloadFile(Downloadable dl)
{
HtmlTableRow row = new HtmlTableRow();
// File name
HtmlTableCell cell = new HtmlTableCell();
cell.InnerHtml = "<a href=\"FileTransferDownload.aspx?file=" + dl.Id + "\" target=\"_blank\">" + dl.FileName + "</a>";
row.Cells.Add(cell);
// Version
cell = new HtmlTableCell();
cell.InnerText = dl.Version.ToString();
row.Cells.Add(cell);
// Upload date
cell = new HtmlTableCell();
cell.InnerText = dl.UploadedOn.ToString();
row.Cells.Add(cell);
return row;
}
您可能需要调整它以适合您正在做的事情,但它显示了我使用的链接格式。
You may need to tweak it to fit exactly what you are doing, but it shows the link format I use.
这篇关于文件没有下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文