display images without having them on the disk?

Discussion in 'ASP .Net' started by Yoramo, Feb 24, 2004.

  1. Yoramo

    Yoramo Guest

    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.
    Yoramo, Feb 24, 2004
    #1
    1. Advertising

  2. Yoramo

    white sheng Guest

    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();
    }
    white sheng, Feb 24, 2004
    #2
    1. Advertising

  3. Yoramo

    Yoramo Guest

    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" <> wrote in message
    news:ec0hGnq%...
    > 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();
    > }
    >
    >
    Yoramo, Feb 24, 2004
    #3
  4. 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" <yoramo@[NOSPAM]hotmail.com> wrote in message
    news:#8fDPEx#...
    > 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" <> wrote in message
    > news:ec0hGnq%...
    > > 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();
    > > }
    > >
    > >

    >
    >
    Kevin Spencer, Feb 25, 2004
    #4
  5. Yoramo

    Yoramo Guest

    Hello Kevin

    How does it know to place the image in a specific IMG tag or a Image button?

    yoramo

    "Kevin Spencer" <> wrote in message
    news:u2vIMv7%...
    > 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" <yoramo@[NOSPAM]hotmail.com> wrote in message
    > news:#8fDPEx#...
    > > 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" <> wrote in message
    > > news:ec0hGnq%...
    > > > 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();
    > > > }
    > > >
    > > >

    > >
    > >

    >
    >
    Yoramo, Feb 25, 2004
    #5
  6. <img src="ImageMaker.aspx">

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Yoramo" <yoramo@[NOSPAM]hotmail.com> wrote in message
    news:etKOln9#...
    > Hello Kevin
    >
    > How does it know to place the image in a specific IMG tag or a Image

    button?
    >
    > yoramo
    >
    > "Kevin Spencer" <> wrote in message
    > news:u2vIMv7%...
    > > 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" <yoramo@[NOSPAM]hotmail.com> wrote in message
    > > news:#8fDPEx#...
    > > > 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" <> wrote in message
    > > > news:ec0hGnq%...
    > > > > 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();
    > > > > }
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Kevin Spencer, Feb 25, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jas Shultz
    Replies:
    0
    Views:
    930
    Jas Shultz
    Dec 3, 2003
  2. Mladen Jablanovic via .NET 247

    Sending generated Office documents without saving them to disk

    Mladen Jablanovic via .NET 247, May 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    278
    avnrao
    May 7, 2004
  3. keithb
    Replies:
    0
    Views:
    386
    keithb
    May 8, 2006
  4. Anonieko

    HttpHandlers - Learn Them. Use Them.

    Anonieko, Jun 15, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    504
    tdavisjr
    Jun 16, 2006
  5. Replies:
    12
    Views:
    496
    santosh
    Nov 15, 2006
Loading...

Share This Page