public class FileOpen : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{

int DocumentId=System.Convert.ToInt32(Request.QueryString.Get("DocumentId"));

SqlDataReader DBContent = FetchContent(DocumentId); DBContent.Read();
string filename = (string)DBContent["FileName"];
filename = System.Web.HttpUtility.UrlEncode(filename,Encoding.UTF8);
Response.AddHeader("Content-Disposition","attachment;filename="+filename);
Response.ContentType = (string)DBContent["ContentType"];
Response.OutputStream.Write((byte[])DBContent["Content"], 0,System.Convert.ToInt32(DBContent["ContentSize"])); Response.Flush();
Response.End();
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
public SqlDataReader FetchContent(int DocumentId)
{
SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings.Get("ConnectionString2"));
SqlCommand Command = new SqlCommand("Select * From TIPS Where DocumentId=@DocumentId",Connection); SqlParameter Param1=new SqlParameter("@DocumentId", SqlDbType.Int);
Param1.Value = DocumentId;
Command.Parameters.Add(Param1);
Connection.Open(); return Command.ExecuteReader(CommandBehavior.CloseConnection);
}

解决方案 »

  1.   

    http://sz.luohuedu.net/xml/ShowDetail.asp?id=EY1XLDYV-PIDF-43LO-1WFL-FMY5ALE1F635个人建议保存文件路径,将文件保存到服务器的专门目录中,负责数据库保存太多的文件,速度会很慢的。
      

  2.   

    我有给我你的邮箱吧,不过我的是ASP.NET的
      

  3.   

    [email protected]
    要源码的哦,谢了,呵呵
      

  4.   

    [email protected]
    我也想要
      

  5.   

    如果每个文件都不是很大,我觉得存数据库好点。如果文件有的很大,就考虑存路径。
    存DOC等文件要读取流。很多例子。孟老大的网站那里也有。
      

  6.   

    建议数据库里面存FTP的地址,如果直接存数据流,这样下载跟HTTP没啥区别,意义不太大哦