473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to realize a C# page that give back an image instead of an html page

Good morning,
I have a static html page where I want to load image that day to day
are in a different path,
to achieve this I would want that the link point to a c# page where I
create dinamically the new url,
but how I can arrange a c# page that give back an image and not an html
page ?
Can you help me to realize this ??

Many Thanks,

Eng. Antonio D'Ottavio
www.etantonio.it/en

Dec 12 '06 #1
3 1265
Change the Response.ContentType of the page to be whatever it needs to
be for the image type you have (ie "image/jpeg") then use a
BinaryWriter that writes to Response.OutputStream.

On Dec 12, 10:16 am, "Etantonio" <etanto...@gmail.comwrote:
Good morning,
I have a static html page where I want to load image that day to day
are in a different path,
to achieve this I would want that the link point to a c# page where I
create dinamically the new url,
but how I can arrange a c# page that give back an image and not an html
page ?
Can you help me to realize this ??

Many Thanks,

Eng. Antonio D'Ottaviowww.etantonio.it/en
Dec 12 '06 #2

Instead of using a BinaryWriter and Response.OutputStream you can just
use Response.WriteFile. Same result, less code.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 12 Dec 2006 08:06:45 -0800, "Michael Letterle"
<mi**************@gmail.comwrote:
>Change the Response.ContentType of the page to be whatever it needs to
be for the image type you have (ie "image/jpeg") then use a
BinaryWriter that writes to Response.OutputStream.

On Dec 12, 10:16 am, "Etantonio" <etanto...@gmail.comwrote:
>Good morning,
I have a static html page where I want to load image that day to day
are in a different path,
to achieve this I would want that the link point to a c# page where I
create dinamically the new url,
but how I can arrange a c# page that give back an image and not an html
page ?
Can you help me to realize this ??

Many Thanks,

Eng. Antonio D'Ottaviowww.etantonio.it/en
Dec 12 '06 #3
Thanks for your reply.
Using your suggestion I arranged the following code in file
http://www.etantonio.it/Temp/Trad.aspx

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<%@ Page Language="c#" Trace="true" Debug="true" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Drawing" %>

<script runat="server">
void Page_Load(Object Src, EventArgs E )
{
if (!Page.IsPostBack)
{
String sAddressTime = "http://www.etantonio.it/images/zh.gif";

HttpWebRequest wreq;
HttpWebResponse wresp;
Stream mystream;
Bitmap bmp;
bmp = null;
mystream = null;
wresp = null;
try
{
wreq = (HttpWebRequest)WebRequest.Create(sAddressTime);

wresp = (HttpWebResponse)wreq.GetResponse();
if ((mystream = wresp.GetResponseStream()) != null)
{
Response.Clear();
Response.ContentType = "image/jpeg";
Response.StatusCode = 200;
Bitmap bmpOriginal = new Bitmap( "yourimage.jpg" );
bmp = new Bitmap(mystream);
bmp.Save( Response.OutputStream, bmp.RawFormat );
bmp.Dispose();
bmp = null;
Response.Close();
return;
}
}
finally
{
if (mystream != null)
mystream.Close();
if (wresp != null)
wresp.Close();
}
}
}
</script>
<html><head>/head><body ></body></html>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
that it is called from a simple html file named CallTrad.aspx
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Untitled Document</title>
</head>

<body>
<img src="http://www.etantonio.it/Temp/Trad.aspx" />
</body>
</html>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
the result is that I've not the image I require,
I simply have a blank pge but with no image, any suggestion to me ??
Thanks

Antonio D'Ottavio
www.etantonio.it/en

Dec 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Johann Blake | last post by:
Hi, I have come across a rather bizarre problem using the TcpClient to retrieve a web page. I use the TcpClient in conjunction with a StreamWriter to write a HTTP request to the web site. The...
5
by: murrayatuptowngallery | last post by:
I'm caught in a classic finger-pointing situation. My hosting company's server appears to be automatically inserting JS tags into a JS-free html page that has an image inked to a 2nd page with...
3
by: Mike Dee | last post by:
Hi, I'm having an issue with the status bar in Mozilla and Netscape showing that it is still waiting on the page to load even after it is finished. This problem does NOT occur with IE. In...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
42
by: smerf | last post by:
Using javascript, is there a way to trap an external page inside a frame? I've seen scripts to break out of frames, but nothing to keep a page trapped in a frame.
4
by: Etantonio | last post by:
Good morning, I have a static html page where I want to load image that day to day are in a different path, to achieve this I would want that the link point to a c# page where I create...
2
by: eholz1 | last post by:
Hello PHP Group, I have a php page that calls another php page to load a image from a database (mysql) in to the calling page. It works like this: first_view.php has <img src="image.php?img=5"...
38
by: ted | last post by:
I have an old link that was widely distributed. I would now like to put a link on that old page that will go to a new page without displaying anything.
7
by: amishguy | last post by:
Hello, I am having an issue with a site I'm creating right now. I have had this issue before and I would like to figure out what the solution is instead of using workarounds as I have in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.