下载或保存

 <asp:TemplateColumn HeaderText="查看">
<ItemTemplate>
<a href='<%#String.Format("download.aspx?filename={0}", DataBinder.Eval(Container.DataItem, "filename2"), DataBinder.Eval(Container.DataItem, "filename"))%>' target=_blank>查看</a>
</ItemTemplate>
</asp:TemplateColumn>
--------------------------------------------
download.aspx

<%@ Page Inherits="www.MyCodeBehind" Src="download.cs" %>

<html>
<head>
<title>文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<link rel="stylesheet" href="Style.css" type="text/css">
<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>

<form runat="server">

</form>

</body>
</html>
-------------------------------------------
download.cs

using System;
using System.Data;
using System.Data.OleDb;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace www
{
 public class MyCodeBehind : Page
 {
  public DataGrid     MyList;
        public DropDownList DropDownList1;
  public DropDownList DropDownList2;
        public TextBox   TextBox1;
  public LinkButton   btnFirst;
  public LinkButton   btnPrev;
  public LinkButton   btnNext;
  public LinkButton   btnLast;
  public Label     lblCurrentPage;
  public Label     lblPageCount;
  public Label     lblRecordCount;
  public TextBox    txtIndex;
  public Label label1;

  public int PageCount,RecordCount; 

                public DataRow dr;
 
  
  private void Page_Load(Object sender, EventArgs e)   
  {  
  
   if(!IsPostBack)
   {
System.IO.FileInfo file = new System.IO.FileInfo("D:/webpro/prod/zsfile/"); 
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
string filename = Request.QueryString["filename"];

string filename2 = Request.QueryString["filename"];
string nowDSN=ConfigurationSettings.AppSettings["scrbb"];
SqlConnection MyConnection=new SqlConnection(nowDSN);
SqlDataAdapter myCommand=new SqlDataAdapter("SELECT filename FROM scpc WHERE filename2='" + filename2 +"'", MyConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "scpc");
//if(ds.Tables["uploadfile"].Rows.Count > 0)
//{
 dr = ds.Tables["scpc"].Rows[0];
 filename = ds.Tables["scpc"].Rows[0]["filename"].ToString();
//}

//string filename = Server.MapPath("../uploadfile/" + s);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(filename));
Response.WriteFile(file+filename);
Response.End();
   
                              DataBind();
   }
  }      

 }
}
-----------------------------------------
方式二:

<asp:TemplateColumn HeaderText="按右鍵下載" SortExpression="filename">
<ItemTemplate>
<a href='<%#String.Format("../uploadfile/{0}", DataBinder.Eval(Container.DataItem, "filename"))%>' target=_blank title="下載"><%#String.Format("{0}", DataBinder.Eval(Container.DataItem, "filename"))%></a>
</ItemTemplate>
</asp:TemplateColumn>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值