protected void lbtnDownload_Click(object sender, EventArgs e)
{
string strPath ="" //获得附件路径 if (strPath != "")
{
FileInfo FInfo = new FileInfo(Server.MapPath(strPath)); //使用获得的路径实例化FileInfo对象
if (FInfo.Exists) //判断附件是否存在
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FInfo.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", FInfo.Length.ToString());
Response.WriteFile(FInfo.FullName); //将指定的附件写入输出流
Response.Flush(); //向客户发送当前所有缓冲的输出 }
}
我将附件放在项目里的一个文件夹里,现在我想点击<asp:LinkButton>按钮时,就下载此附件,请问怎么获得这个在项目里的路径啊??还有望大狭指教下我的下载代码有问题没?/多谢~~(注:项目是放在E:\project 附件是放在项目里即:E:\project\fujian里的 )
{
string strPath ="" //获得附件路径 if (strPath != "")
{
FileInfo FInfo = new FileInfo(Server.MapPath(strPath)); //使用获得的路径实例化FileInfo对象
if (FInfo.Exists) //判断附件是否存在
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FInfo.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", FInfo.Length.ToString());
Response.WriteFile(FInfo.FullName); //将指定的附件写入输出流
Response.Flush(); //向客户发送当前所有缓冲的输出 }
}
我将附件放在项目里的一个文件夹里,现在我想点击<asp:LinkButton>按钮时,就下载此附件,请问怎么获得这个在项目里的路径啊??还有望大狭指教下我的下载代码有问题没?/多谢~~(注:项目是放在E:\project 附件是放在项目里即:E:\project\fujian里的 )
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货