asp.net上传下载,自我测试
来源:互联网 发布:淘宝达人手机发帖 编辑:程序博客网 时间:2024/06/11 15:44
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;
using System.IO;
namespace sz
{
/// <summary>
/// upfile 的摘要说明。
/// </summary>
public class upf : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile upf1;
private void Page_Load(object sender, System.EventArgs e)
{
}
public void submit_click(object sender,System.EventArgs e)
{
if(upf1.PostedFile.ContentLength>0)
{
string[] FileSplite = upf1.PostedFile.FileName.Split('//');//取得文件名称
string fn = FileSplite[FileSplite.Length -1];
string ft = upf1.PostedFile.ContentType;
FileInfo fi=new FileInfo(upf1.PostedFile.FileName);
FileStream fs=fi.OpenRead();
byte[] bytes=new byte[fs.Length];
fs.Read(bytes,0,Convert.ToInt32(fs.Length));
string conn = ConfigurationSettings.AppSettings["myConn9"];
SqlConnection cn = new SqlConnection(conn);
SqlCommand cm=new SqlCommand();
cm.Connection=cn;
cm.CommandType=CommandType.Text;
if(cn.State==0) cn.Open();
cm.CommandText="insert into sz_file (filename,filetype,filedata) values ('"+fn+"','"+ft+"',@file)";
SqlParameter spFile=new SqlParameter("@file",SqlDbType.Image);
spFile.Value=bytes;
cm.Parameters.Add(spFile);
cm.ExecuteNonQuery();
}
}
public void down_click(object sender,System.EventArgs e){
string conn = ConfigurationSettings.AppSettings["myConn9"];
string StrSql = "select * from sz_file";
SqlConnection MyConnection = new SqlConnection(conn);
SqlCommand MyCommand = new SqlCommand();
MyCommand.Connection = MyConnection;
SqlDataAdapter objDataAdapter = new SqlDataAdapter();
objDataAdapter.SelectCommand = MyCommand;
DataSet objectSet = new DataSet();
MyCommand.CommandText = StrSql;
objDataAdapter.Fill(objectSet,"a");
DataRow dr=objectSet.Tables["a"].Rows[0];
byte[] File=null;
File=(byte[])dr["filedata"];
Response.AddHeader("Content-Disposition", "attachment;filename="+HttpUtility.UrlEncode(dr["filename"].ToString(),System.Text.Encoding.UTF8));
Response.ContentType=dr["filetype"].ToString();
Response.BinaryWrite(File);
}
#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
}
}
- asp.net上传下载,自我测试
- asp.net 上传下载文件
- ASP.NET文件上传下载
- Asp.net 文件上传下载
- ASP.NET附件上传下载
- ASP.NET上传下载
- ASP.NET上传下载文件
- asp.net 上传下载
- ASP.NET附件上传下载
- ASP.NET上传下载
- ASP.NET中上传下载文件
- ASP.NET中上传下载文件
- ASP.NET中上传下载文件
- ASP.NET中上传下载文件
- ASP.NET中上传下载文件
- ASP.NET中上传下载文件
- ASP.NET中上传下载文件
- ASP.NET中上传下载文件
- 批量导入的修改
- [原创]使用DataList数据修改,保存,取消
- RTC Client API的特性
- RTC Client Objects and Interface
- Java 编程技术中汉字问题的分析及解决
- asp.net上传下载,自我测试
- 产生素数的算法
- 利用 SLI进行基于主机的 Web 服务集成
- Eclipse配置问题集锦
- jspSmartUpload上传下载全攻略
- 我的编译EZX例子的经历
- 4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000F0000000
- 重启IIS
- 自动切换网络访问脚本(不完全版)