473,320 Members | 1,865 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,320 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
4 1395

microsoft.public.dotnet.languages.csharp
Tuesday, December 12, 2006 10:16 AM
Please do not cross post.
http://groups-beta.google.com/group/...67fd4b2576dde6
"Etantonio" <et*******@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
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 #2
I'm not sure that this is a cross post.

The detail is a little ambiguous really. He could mean and aspx c# based
webform being used to generate html to get the desired result, in which case
posting here would be appropriate ?!?
"sloan" <sl***@ipass.netwrote in message
news:u6**************@TK2MSFTNGP02.phx.gbl...
>
microsoft.public.dotnet.languages.csharp
Tuesday, December 12, 2006 10:16 AM
Please do not cross post.
http://groups-beta.google.com/group/...67fd4b2576dde6
"Etantonio" <et*******@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
>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 #3
Hi,

Etantonio wrote:
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,
In order to return an image to a Request instead of HTML code, you can
use the following (typically in Page_Load):

Response.Clear();
Response.ContentType = "image/jpeg";
Response.StatusCode = 200;
Bitmap bmpOriginal = new Bitmap( "yourimage.jpg" );
bmpOriginal.Save( Response.OutputStream, bmpOriginal.RawFormat );
bmpOriginal.Dispose();
bmpOriginal = null;
Response.Close();
return;

It is not strictly necessary to Clear and Close the Response, but that's
safer.

On the client, simply use (for example)
<img src="yourpage.aspx?picname=yourimage.jpg" />

Note that using an ASHX custom HTTP handler instead of an ASPX is more
efficient for this kind of things, because then you avoid the whole
event wiring generated by the Page class.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Dec 12 '06 #4
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 #5

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.
3
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...
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:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.