display images without having them on the disk?

  • Thread starter Thread starter Yoramo
  • Start date Start date
Y

Yoramo

Hello

is it possible to display images on a ASPX without having them on the disk
of the server ?

I have images in a DB and whould like to display them on a web page. writing
them to disk seems very costly.

is it posible to create them in memory and some how give them to the client
to display?

thanks in advance
Yoramo.
 
hi,you can do it just like the following example.

private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection mycon = new SqlConnection("your connection string");
mycon.Open();

int liid = int.Parse(Request.QueryString["id"]);
string sqlText = "SELECT img_name, img_data, img_contenttype FROM image1
where id="+liid;
SqlCommand MyCommand = new SqlCommand (sqlText, mycon);
SqlDataReader dr =MyCommand.ExecuteReader();
if(dr.Read())
{
Response.ContentType = (dr["img_contenttype"].ToString());
Response.BinaryWrite((byte[])dr["img_data"]);
}
mycon.Close();
}
 
hello

Thanks for your replay.
can you show me how whould the aspx file look like for such a code to
work?

Yoramo.
 
He already did. There is no Template HTML. It simply sends an image. You
include a reference to that page as the URL for an image tag in another
page.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Yoramo said:
hello

Thanks for your replay.
can you show me how whould the aspx file look like for such a code to
work?

Yoramo.


white sheng said:
hi,you can do it just like the following example.

private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection mycon = new SqlConnection("your connection string");
mycon.Open();

int liid = int.Parse(Request.QueryString["id"]);
string sqlText = "SELECT img_name, img_data, img_contenttype FROM image1
where id="+liid;
SqlCommand MyCommand = new SqlCommand (sqlText, mycon);
SqlDataReader dr =MyCommand.ExecuteReader();
if(dr.Read())
{
Response.ContentType = (dr["img_contenttype"].ToString());
Response.BinaryWrite((byte[])dr["img_data"]);
}
mycon.Close();
}
 
Hello Kevin

How does it know to place the image in a specific IMG tag or a Image button?

yoramo

Kevin Spencer said:
He already did. There is no Template HTML. It simply sends an image. You
include a reference to that page as the URL for an image tag in another
page.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Yoramo said:
hello

Thanks for your replay.
can you show me how whould the aspx file look like for such a code to
work?

Yoramo.


white sheng said:
hi,you can do it just like the following example.

private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection mycon = new SqlConnection("your connection string");
mycon.Open();

int liid = int.Parse(Request.QueryString["id"]);
string sqlText = "SELECT img_name, img_data, img_contenttype FROM image1
where id="+liid;
SqlCommand MyCommand = new SqlCommand (sqlText, mycon);
SqlDataReader dr =MyCommand.ExecuteReader();
if(dr.Read())
{
Response.ContentType = (dr["img_contenttype"].ToString());
Response.BinaryWrite((byte[])dr["img_data"]);
}
mycon.Close();
}
 
<img src="ImageMaker.aspx">

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Yoramo said:
Hello Kevin

How does it know to place the image in a specific IMG tag or a Image button?

yoramo

Kevin Spencer said:
He already did. There is no Template HTML. It simply sends an image. You
include a reference to that page as the URL for an image tag in another
page.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Yoramo said:
hello

Thanks for your replay.
can you show me how whould the aspx file look like for such a code to
work?

Yoramo.


hi,you can do it just like the following example.

private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection mycon = new SqlConnection("your connection string");
mycon.Open();

int liid = int.Parse(Request.QueryString["id"]);
string sqlText = "SELECT img_name, img_data, img_contenttype FROM
image1
where id="+liid;
SqlCommand MyCommand = new SqlCommand (sqlText, mycon);
SqlDataReader dr =MyCommand.ExecuteReader();
if(dr.Read())
{
Response.ContentType = (dr["img_contenttype"].ToString());
Response.BinaryWrite((byte[])dr["img_data"]);
}
mycon.Close();
}
 
Back
Top