저장

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Configuration;

namespace WebApplicationTest

{

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

DataSet1TableAdapters.ImageTableTableAdapter adapter = new WebApplicationTest.DataSet1TableAdapters.ImageTableTableAdapter();

byte[] bt = this.FileUpload1.FileBytes; //이미지를 바이트로 저장하기

DataSet1.ImageTableDataTable dt = new DataSet1.ImageTableDataTable();

DataSet1.ImageTableRow row = dt.NewImageTableRow();

row.ImageContent = bt;

dt.AddImageTableRow(row);

adapter.Update(dt);

}

}

불러오기

InHandler.ashx 파일생성

<%@ WebHandler Language="C#" Class="InHandler" %>

using System;

using System.Web;

public class InHandler : IHttpHandler {

public void ProcessRequest (HttpContext context) {

가져오기 쿼리…

System.Data.DataTable dt = op.GetDataTable(); //가져온 데이터

byte[] pic = (byte[])dt.Rows[0]["FILE_ATTACH"];//이미지를 저장하고 있는 필드

context.Response.OutputStream.Write(pic, 0, pic.Length);

context.Response.End();

}

public bool IsReusable {

get {

return true;

}

}

}

실제사용은 간단하게

<img src=" InHandler.ashx"> 이렇게 하면 끝~

+ Recent posts