下载问题
我想做一个下载功能但不知道怎么做?我直接给加连接到下载的路径,但是没有弹出下载的对话框,而是显示无法找到网页.请各位指点一下应该怎么做?最好有代码
下载问题
using System;using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using
using System.Data.SqlClient;
public partial class download : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["id"];
string sql = "select Accessory from mail where ID = +id";
SqlConnection conn = Database.GetOpenDatabase();
SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);
if(ds.Tables[0].Rows.Count>0)
{
//string path = ds.Tables[0].Rows[0]["Accessory"].ToString();
string path = "//download//jianli.doc";
if (path != null)
{
FileDownloadByFullName(path);
}
}
}
public static void FileDownloadByFullName(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(FullFileName);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = false;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.ASCII));
HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
}
但是老出现找不到路径,请帮忙看看