using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace Delegate
{
public partial class ReadStream :
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// Convert the uploaded file into a binary stream and save it in the database
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(["sql"].ToString());
string strSql="insert into test(timage)values(@images)";//The form of parameters required for saving binary streams
SqlCommand cmd = new SqlCommand(strSql, conn);
();
string filepath = ("~/");
filepath += ;
(filepath);
FileStream fs = new FileStream(filepath, , );//Read the file
BinaryReader br = new BinaryReader(fs);
byte[] photo = ((int));
();
();
("@images", , );//Set parameters
["@images"].Value = photo;//Set the value
if (() == 1)
{
("Add successfully!");
}
();
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(["sql"].ToString());
();
string strSql = "select top 1 timage from test";
SqlCommand cmd = new SqlCommand(strSql, conn);
SqlDataReader dr = ();
if (())
{
byte[] by = (byte[])dr[0];
("Content-Disposition", "attachment; filename=");//Set the read file header
("Content-Length", ());
= "text/plain";//Set the output type. It can be saved in the database. Dynamic implementation type
(by, 0, ); //Output
();
}
();
}
}
}