一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

asp.net 上傳下載輸出二進制流實現(xiàn)代碼

復制代碼 代碼如下:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.IO;
namespace Delegate
{
public partial class ReadStream : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 將上傳的文件轉換成二進制流保存在數(shù)據(jù)庫
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sql"].ToString());
string strSql="insert into test(timage)values(@images)";//保存二進制流的方式需參數(shù)的形式
SqlCommand cmd = new SqlCommand(strSql, conn);
conn.Open();
string filepath = Server.MapPath("~/");
filepath += FileUpload1.FileName;
FileUpload1.SaveAs(filepath);
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);//讀取文件
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
cmd.Parameters.Add("@images", SqlDbType.Binary, photo.Length);//設置參數(shù)
cmd.Parameters["@images"].Value = photo;//設置值
if (cmd.ExecuteNonQuery() == 1)
{
Response.Write("添加成功!");
}
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sql"].ToString());
conn.Open();
string strSql = "select top 1 timage from test";
SqlCommand cmd = new SqlCommand(strSql, conn);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.Read())
{
byte[] by = (byte[])dr[0];
Response.AddHeader("Content-Disposition", "attachment; filename=ceshi.txt");//設置讀取的文件頭
Response.AddHeader("Content-Length", by.Length.ToString());
Response.ContentType = "text/plain";//設置輸出類型 這里可以保存在數(shù)據(jù)庫中 動態(tài)實現(xiàn)類型
Response.OutputStream.Write(by, 0, by.Length); //輸出
Response.Flush();
}
conn.Close();
}
}
}

AspNet技術asp.net 上傳下載輸出二進制流實現(xiàn)代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: vvvv98国产成人综合青青 | 91高清国产| 一区二区三区视频 | 亚洲大成色www永久网 | 久久九九有精品国产56 | 色吧综合 | 人人洗澡人人洗澡人人 | 欧美日韩激情一区二区三区 | 国产99精品| 色宅男中文字幕亚洲专区 | 劲爆欧美第一页 | 久久91亚洲精品中文字幕 | 激情综合网婷婷 | 成人精品视频 | 中文字幕一区二区在线观看 | 99精品视频在线观看re | 国产午夜精品福利久久 | 色播在线视频 | 亚洲精品手机在线观看 | 91麻豆文化传媒有限公司 | 午夜在线日韩免费精品福利 | 黄色视屏在线免费观看 | 亚洲综合日韩欧美一区二区三 | 国产综合视频在线观看一区 | 91麻豆精品国产片在线观看 | 自拍偷自拍亚洲精品被多人伦好爽 | 中文字幕一区二区三区四区五区人 | 精品视频在线播放 | 操吊视频 | 黄视频在线 | 国产xxxxx| 亚洲午夜小视频 | 六月丁香久久 | 一区二区三区四区免费视频 | 亚洲精品影院久久久久久 | 亚洲一二四区性毛片1在线 亚洲一级黄色毛片 | 色哟哟网 | 中国一级特黄真人毛片免 | 精品国产污网站在线观看15 | 久久综合久久伊人 | 超pen个人视频国产免费观看 |