473,387 Members | 1,569 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,387 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 1397

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.