//获取文件路径
string filepath = ((Label)e.Item.FindControl("lbFileUrl")).Text;
//下载框
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filepath, System.Text.Encoding.UTF8));
不行啊,试过了,没有弹出保存框啊?
@光哥IT: 写在下载按钮事件里面
@MR.豆耐特: 是呀。。。
@MR.豆耐特:
protected void btnDaoChu_Click(object sender, EventArgs e)
{
try
{
string filepath = "D:\\Personal\\zhengguang.liu\\桌面\\Chap0101.xls";
//下载框
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filepath, System.Text.Encoding.UTF8));
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream("D:\\Personal\\zhengguang.liu\\桌面\\Chap0101.xls", FileMode.Create));
document.Open();
BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);
document.Add(new Paragraph("sdfdfdf", fontChinese));
iTextSharp.text.Image jpeg = iTextSharp.text.Image.GetInstance(Server.MapPath("~/.") + "\\images\\14.gif");
document.Add(jpeg);
PdfPTable table = new PdfPTable(datatable.Columns.Count);
for (int i = 0; i < datatable.Rows.Count; i++)
{
for (int j = 0; j < datatable.Columns.Count; j++)
{
table.AddCell(new Phrase(datatable.Rows[i][j].ToString(), fontChinese));
}
}
document.Add(table);
document.Close();
}
catch (DocumentException de)
{
Response.Write(de.ToString());
}
}