display images without having them on the disk?

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.
 
W

white sheng

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();
}
 
Y

Yoramo

hello

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

Yoramo.
 
K

Kevin Spencer

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();
}
 
Y

Yoramo

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();
}
 
K

Kevin Spencer

<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();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top