Home All Groups Group Topic Archive Search About

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

Author
16 Dec 2006 10:42 AM
Etantonio
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 ?

I tried with the following code but the resulting page is empty


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>
///////////////////////////////////////////////////////////////////////////­/////////////////////////////////////////////////////////////////////////






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

Author
16 Dec 2006 12:04 PM
Cor Ligthert [MVP]
Etantonio, sending your question to all newsgroups, will only make the
change less that you get an answer, this newsgroup has nothing to do with
webpages beside as they need a datase, which is not in your question.


"Etantonio" <etanto***@gmail.com> schreef in bericht
news:1166265764.725083.276110@l12g2000cwl.googlegroups.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 ?

I tried with the following code but the resulting page is empty


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>
///////////////////////////////////////////////////////////////////////////­/////////////////////////////////////////////////////////////////////////






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

AddThis Social Bookmark Button