Re: How to set Image source from memorystream?

B

B

Kevin,
Is this page created on the fly in page_load? Or, is one created in the
project and then just instatiated as many times as needed?

Can you point me to some code that could demonstrate this technique?

I need to display an image which is save in a db with a caption from the db
underneth the image. I can have 0 to many images on the page...

Thanks in advance.
Blake
 
Y

Yan-Hong Huang[MSFT]

Hi Blake,

Thanks very much for your contribution. :)

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Blake Versiga" <.>
!References: <[email protected]>
<[email protected]>
<#[email protected]>
!Subject: Re: How to set Image source from memorystream?
!Date: Wed, 13 Aug 2003 06:28:30 -0500
!Lines: 136
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <[email protected]>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: aux-217-3-232.dallas.net 209.217.3.232
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:167402
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!This is what I do an it works great
!
!private void Page_Load(object sender, System.EventArgs e)
!{
!// Put user code to initialize the page here
!if (Page.Request.QueryString["ID"] != null)
!{
!SqlConnection mySqlConnection = new SqlConnection("data source=WEBSERVER;"+
!"initial catalog=dbnamd;"+
!"password=blah;"+
!"persist security info=True;"+
!"user id=aspnet;packet size=4096");
!SqlCommand mySqlCommand = new SqlCommand("Select [Image], ImageSize from
!images where ImageId = '" +
!Page.Request.QueryString["ID"] + "'", mySqlConnection);
!mySqlConnection.Open();
!SqlDataReader myReader;
!myReader = mySqlCommand.ExecuteReader();
!// Always call Read before accessing data.
!try
!{
!if (myReader.Read())
!{
!MemoryStream MyMemoryStream = new MemoryStream();
!int FileSize = myReader.GetInt32(1);
!byte[] Buffer = new byte[(int)FileSize];
!myReader.GetBytes(0, 0, Buffer, 0, FileSize);
!MyMemoryStream.Read(Buffer, 0, (int)FileSize);
!MyMemoryStream.Close();
!Response.BinaryWrite(Buffer);
!//.OutputStream.ToString() = myReader["Image"].ToString();
!}
!}
!finally
!{
!mySqlConnection.Close();
!myReader.Close();
!}
!}
!}
!
!in the calling application connect to the db and select your data
! then do something like this. I have a literal control to hold the
!dynamic picture area
!
!SqlDataReader myReader;
!myReader = mySqlCommand.ExecuteReader();
!try
!{
!// Always call Read before accessing data.
!theHtml = "";
!litPhotos.Text = "";
!while (myReader.Read())
!{
!theHtml = "<IMG ";
!if (!myReader.IsDBNull(2))
!theHtml += "height=\"" + myReader.GetInt32(2).ToString() + "\" ";
!if (!myReader.IsDBNull(3))
!theHtml += "width=\"" + myReader.GetInt32(3).ToString() + "\" ";
!theHtml += "alt=\"" + myReader["Description"].ToString().Trim() +
!"\" src=\"" + "DBImage.aspx?ID=" + myReader["ImageId"].ToString()+
!"\"><br>" + myReader["Description"].ToString().Trim()+
!"<br><br>" + "\n";
!litPhotos.Text = theHtml + litPhotos.Text;
!}
!litPhotos.Text = "<center>" + litPhotos.Text + "</center>";
!}
!finally
!{
!// always call Close when done reading.
!myReader.Close();
!}
!
!
!> Kevin,
!> Is this page created on the fly in page_load? Or, is one created in the
!> project and then just instatiated as many times as needed?
!>
!> Can you point me to some code that could demonstrate this technique?
!>
!> I need to display an image which is save in a db with a caption from the
!db
!> underneth the image. I can have 0 to many images on the page...
!>
!> Thanks in advance.
!> Blake
!>
!> !> > Hi Terry,
!> >
!> > Because the page that sends the image must set the Response.ContentType
!> > property to "image/gif" you MUST have an ASPX page that displays only
!the
!> > image. That page can be referenced in another ASPX page as if it were
an
!> > actual image. Example:
!> >
!> > <img src="Image.aspx">
!> >
!> > HTH,
!> >
!> > Kevin Spencer
!> > Microsoft FrontPage MVP
!> > Internet Developer
!> > http://www.takempis.com
!> > There is an exception to every rule...
!> > Except this one.
!> >
!> > !> > > Hi,
!> > > 1- How to set Image source from memorystream in HTML page without
!> > saving
!> > > it in the
!> > > server and i musnt be alone the page ( with other WebControls
)
!> > > 2 - How to save image from memorystream to Client Machin in web
!> > > application
!> > >
!> > > Note: i know how to save it from the momery to the page but it only
!> shows
!> > > the image .
!> > >
!> > > Response.ContentType="image/gif";
!> > > // Send the image to the viewer.
!> > > b.Save(Response.OutputStream , b.RawFormat );
!> > > thks in Advance,
!> > > Terry.
!> > >
!> > >
!> >
!> >
!>
!>
!
!
!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top