我做了个下载的程序,就是将上传的文件路径传到数据库中,然后通过数据库中的路径将文件下载到客户端,但是当下载时会先下载当前页面的程序,而不是数据库中文件的路径。有没有解决办法!!我是菜鸟!!这是我下载的代码,请大虾指点:
int id = int.Parse(Request.QueryString["id"]);
DataTable dtd = message.getallbyid(id);
p = dtd.Rows[0]["filepath"].ToString();
String FullFileName = System.Web.HttpContext.Current.Server.MapPath(p);
FileInfo DownloadFile = new FileInfo(FullFileName);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.Buffer = false;
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.End();
使用:
Response.Redirect(p);
试试!