Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 29th, 2004, 08:19 AM
Authorized User
Join Date: Nov 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to koneruvijay
Default Dynamically adding Image to web page

I am having a page where i have to show image based on the Id in which he logged in

Just like a profile if user logged in i have to show his picture and his details
Can any body giv me some sample code regarding this and the best sample page regarding this.


Old January 29th, 2004, 09:46 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts

I did something similar a long time ago. I have a sign in page that displayed a picture next to your name. I don't have the code anymore. But I still know how it works.

You can save the name of the pictures into a column on the table and have the code like this:

<img src=images/" & row("image_name") & " />

Old January 30th, 2004, 09:25 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts

I found this on one project that I set up when i was first learning asp.net. It's messy but you should get the idea. Once you have a dataset you could use this code:

sResults.Append("<table width=100% border=0 cellpadding=0 cellspacing=0>")
        sResults.AppendFormat("<tr><td><h3>{0}</h3></td></tr></table><br>", getHAdata())

        sResults.Append("<table width=100% border=0 cellpadding=2 cellspacing=0>")
        sResults.Append("<tr id=producttable>" & _
            "<td>Model</td><td></td><td align=center width=90>In Stock</td>" & _
            "<td align=center width=90>Price</td><td align=center width=90>Buy</td></tr>")
Dim r As DataRow
        For Each r In objDataSet.Tables("mydatatable").Rows
            sResults.Append("<tr id=products><td width=20>" & _
            "<a class=productlinks href=item.aspx?p=1&i=" & r("prod_id") & ">" & _
            "<img src=images/" & r("prod_id") & ".gif height=35 width=40 border=0 /></a></td>" & _
            "<td><a class=productlinks href=item.aspx?p=1&i=" & r("prod_id") & ">" & getHAdata() & "</a></td>" & _
            "<td id=prodtext>" & r("in_stock") & "</td>" & _
            "<td id=prodtext>" & r("price") & "</td>" & _
            "<td id=prodtext>Buy</td></tr>")


        Return sResults.ToString

Old January 30th, 2004, 11:24 AM
Authorized User
Join Date: Aug 2003
Posts: 18
Thanks: 0
Thanked 1 Time in 1 Post

You can use an aspx page in the image tag like..
<img src="http://mysite/picturegetter.aspx?image=Johnny.jpg">

In your the picturegetter.aspx you must check the image name desired and then stream the image through the response object. Do this through the pageload event in your code behind page. You have NOTHING in the ASPX page.

So, in the pageload event, get your image name using the query string. Then you load the image into a bitmap and stream it out the reponse object. Example below (haven't tested this, but it should give you pretty much what you need)...

Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FileName as String
Dim pic As System.Drawing.Image
Dim myBitMap as System.Drawing.Bitmap

'get image name

'load file

'convert image to bitmap so you have SAVE method

'Now write to response stream
Response.ContentType = "image/jpg"
myBitMap.Save(Response.OutputStream, ImageFormat.Jpeg)

End Sub

I can't remember what all of the imports you really need. In my code I am calling a webservice to deliver the image so its slightly different.

Hope this helps.
Old March 14th, 2004, 08:42 PM
Registered User
Join Date: Mar 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts

Here is another, for performace issue to creating Bitmap everytime..
I'm using both method for conditionally.
(A creating Image object)
ImageOutput = Image.FromFile(ImagePath)
ResponseOutput.ContentType = "image/jpeg"
ImageOutput.Save(ResponseOutput.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)

(B, if getting image from file) --> preferred method as saving A Image Object ^^
ResponseOutput.ContentType = "image/gif"


Similar Threads
Thread Thread Starter Forum Replies Last Post
Events - Adding Dynamically dash dev C# 2005 2 December 5th, 2007 02:05 PM
Adding Controls Dynamically andyj00 C# 0 March 19th, 2007 08:54 AM
dynamically adding objects shawnvb VB How-To 3 February 14th, 2007 03:12 PM
Dynamically adding page breaks Krimboss BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 6th, 2005 10:39 AM
download text or image from web page cjursch Javascript How-To 1 June 12th, 2003 12:30 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.