http://www.csdn.net/expert/topic/1053/1053203.xml?temp=.5867731
解决方案 »
- GridView控件里的第2列的模板列的LinkButton2事件里怎么得到第一列的模板列里的LinkButton1的值?
- 大伙速度来帮忙看看,,,页面自动跳转的问题。。。。急的上火牙痛,,,
- 怎么知道生成了哪些文件?
- 搞了一天了,请问IIS怎么出现如此提示
- 网站使用 paypal 交易时扣手续费 怎么实现或者原理是什么.知道的牛人门帮个忙?谢谢
- ISAPI filter的配置问题。
- 有人想要asp.net(c#)+access的商业网站源代码么?
- 请教SQL语句高手关于联合查询的问题
- 按提交后不想保存控件的值这应该怎么做
- asp.net发布后连不上远程oracle
- 外企高薪招聘!!外企高薪招聘!!dotnet高级工程师
- 求救! 用vb.net做了一个程序,其中使用到mscomm.ocx,打包成安装程序,装到别的机器有的问题,提示错误
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>file</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="file" method="post" enctype="multipart/form-data" runat="server">
<asp:TextBox id="user" style="Z-INDEX: 101; LEFT: 120px; POSITION: absolute; TOP: 142px" runat="server"></asp:TextBox>
<INPUT style="Z-INDEX: 102; LEFT: 120px; POSITION: absolute; TOP: 186px" type="file" id="my_file" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 140px; POSITION: absolute; TOP: 248px" runat="server" Text="Button"></asp:Button>
</form>
<br>
<br>
<a href="download.aspx?id=12">download</a>
</body>
</HTML>
------------------------------------------------------
.cs页面
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;namespace website.other
{
/// <summary>
/// file 的摘要说明。
/// </summary>
public class file : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox user;
protected System.Web.UI.HtmlControls.HtmlInputFile my_file;
protected System.Web.UI.WebControls.Button Button1;
SqlConnection cn;
private void Page_Load(System.Object sender, System.EventArgs e)
{
String strConn=(String)Application["strConn"];
cn=new SqlConnection(strConn);
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(System.Object sender, System.EventArgs e)
{
if (my_file.PostedFile!=null)
{
String strConn=(String)Application["strConn"];
cn=new SqlConnection(strConn);
HttpPostedFile myfile=my_file.PostedFile;
int FileSize=myfile.ContentLength;
string FileName=myfile.FileName.ToString();
string FileType=myfile.ContentType.ToString();
string FileUser=user.Text;
Byte[] FileData=new Byte[FileSize];
Stream str=my_file.PostedFile.InputStream;
str.Read(FileData,0,FileSize);
String strSQL="insert into upload(FileUseraspnet,FileSizeaspnet,FileNameaspnet,FileTypeaspnet,FileDataaspnet) values (@FileUser,@FileSize,@FileName,@FileType,@FileData)"; cn.Open();
SqlCommand cm=new SqlCommand(strSQL,cn);
cm.Parameters.Add(new SqlParameter("@FileUser",SqlDbType.VarChar)).Value=FileUser;
cm.Parameters.Add(new SqlParameter("@FileSize",SqlDbType.Int)).Value=FileSize;
cm.Parameters.Add(new SqlParameter("@FileName",SqlDbType.VarChar)).Value=FileName;
cm.Parameters.Add(new SqlParameter("@FileType",SqlDbType.VarChar)).Value=FileType;
cm.Parameters.Add(new SqlParameter("@FileData",SqlDbType.Image)).Value=FileData; try
{
cm.ExecuteNonQuery();
Response.Write ("<script language=javascript>alert('上传到数据库成功!');parent.location.href='file.aspx'</"+"script>");
}
catch
{
Response.Write ("<script language=javascript>alert('不能成功!');</"+"script>");
}
cm.Connection.Close();
}
}
}
}
----------------------------------------------------------------下载的页面using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace website.other
{
/// <summary>
/// download 的摘要说明。
/// </summary>
public class download : System.Web.UI.Page
{
SqlConnection cn;
private void Page_Load(object sender, System.EventArgs e)
{
string strconn=Application["strConn"].ToString();
cn=new SqlConnection(strconn);
//string str1=ConfigurationSettings.AppSettings["dsn"];
//取得配置文件中appsettings段的值
string sql="select * from upload where Id="+Request["id"];
cn.Open();
SqlCommand cm=new SqlCommand(sql,cn);
SqlDataReader dr;
dr=cm.ExecuteReader();
if (dr.Read())
{
Response.ContentType=dr["FileTypeaspnet"].ToString();
//Response.ContentType="application/octet-stream";
Response.AddHeader("Content-Disposition", "Attachment; FileName="+HttpUtility.UrlEncode(dr["FileNameaspnet"].ToString().Replace('+',' ')));
Response.BinaryWrite((Byte[])dr["FileDataaspnet"]);
}
else
{
Response.Write("下载没有成功");
}
cn.Close();
} #region Web Form Designer generated code
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
}
}