不用特殊指定吧,
string path = Server.MapPath(Request.Params["File"]);
System.IO.FileInfo file = new System.IO.FileInfo(path); // clear the current output content from the buffer
Response.Clear();
// add the header that specifies the default filename for the Download/SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
// add the header that specifies the file size, so that the browser
// can show the download progress
Response.AddHeader("Content-Length", file.Length.ToString());
// specify that the response is a stream that cannot be read by the
// client and must be downloaded
Response.ContentType = "application/octet-stream";
// send the file stream to the client
Response.WriteFile(file.FullName);
// stop the execution of this page
Response.End();

解决方案 »

  1.   

    如果直接从数据库中读,就改一改:/*从数据库读出文件并显示在网页上,str_table_name表要从哪个表中读文件; str_blob_column_name表文件存储的字段名;str_select_condition表检索的条件;一次只能读出一个文件。 */ public void sqltofile(string str_table_name,string str_blob_column_name,string str_select_condition) { //数据库操作 SqlDataReader sdr_file; string str_scn=ConfigurationSettings.AppSettings["str_database_connection"]; cyc_data cd_file=new cyc_data(str_scn); //构造检索语句 string str_scm="select " + str_blob_column_name + " from " + str_table_name + " where " + str_select_condition; SqlCommand scd_file=new SqlCommand(str_scm,cyc_data.scn_databaseconnection); if (cyc_data.scn_databaseconnection.State==ConnectionState.Closed) { try { cyc_data.scn_databaseconnection.Open(); } catch (SqlException e) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Redirect("error.aspx?id=1"); HttpContext.Current.Response.End(); } } //执行查询 try { sdr_file=scd_file.ExecuteReader(CommandBehavior.SequentialAccess); } catch (SqlException e) { sdr_file=null; cyc_data.scn_databaseconnection.Close(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Redirect("error.aspx?id=2"); HttpContext.Current.Response.End(); } //读出文件内容 if (sdr_file.Read()) { try { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType=open_file_application(file_type(str_table_name,str_blob_column_name,str_select_condition)); System.IO.Stream fs=HttpContext.Current.Response.OutputStream; int fileDataCol = 0;  Byte[] b = new Byte[(sdr_file.GetBytes(fileDataCol, 0, null, 0, int.MaxValue))]; sdr_file.GetBytes(fileDataCol, 0, b, 0, b.Length); sdr_file.Close(); cyc_data.scn_databaseconnection.Close(); fs.Write(b,0,b.Length); fs.Close(); HttpContext.Current.Response.End(); } catch (Exception e) { //关闭数据库连接 sdr_file.Close(); cyc_data.scn_databaseconnection.Close(); //打开错误提示页 HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Redirect("error.aspx?id=5"); HttpContext.Current.Response.End(); } } //无法读取或者没有符合条件记录 else { sdr_file.Close(); cyc_data.scn_databaseconnection.Close(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Redirect("error.aspx?id=2"); HttpContext.Current.Response.End(); } }这是一个从sql中读出文件的函数,你看一看。