Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 April 12th, 2007, 06:40 AM
Authorized User
 
Join Date: Apr 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Image Control...!!!!!!!!!!!

Hi Everybody,

im facing a problem with image control on my web page.

im uploading an image; saving it in database and again retrive image from database.

im having an image control, a file upload control,a button to upload, and submit button on my webpage.

i upload any image using file upload, and press upload. in upload button click im saving image file to a server directory named as "images" and then save the image to sql server database (converting image to bytes).

when i want to show that image again; i simply convert bytes to image and save the file to same server directory named as "images" after deleting any existing files; and assign that url say; "~\Images\img.jpg" to my image control.



this practice is fine for one time. when i do it again, it stores right image. but in image control; it shows previous image. when i press F5; then only it shows newly uploaded image.


i tried for it and get stuck up., pls help as its urgent................

thanks in advance..


 
Old April 12th, 2007, 09:16 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

While your approach is technical feasible, it's practically problematic (as you are finding).

1) All that disk IO really hurts performance when you gain nothing from it (i.e. you are not putting the file on disk to save it permanently, just as a temporary storage).

2) Because of the performance issue previously mentioned, you are likely to get two users competing for that single file.

3) Using the file system in a web application has it's own set of problems. You have to fight with permissions issues when you deploy such an application.

You should be able to take the file stream from the upload event and save it directly into the database without going through the file system at all. This will be significantly more efficient. Presuming that you have some identifier for the row that contains the image, you can uniquely identify it.

To retrieve the image, you can create a page or HttpHandler to process an image request. Instead of given a URL like: "/myapp/images/img.jpg", you give one that looks like this: "/myapp/getimage.aspx?imageID=123456". When the page runs, you do these steps:

 - Clear the response buffer (so there isn't anything emitted to start)
 - Change the Response.ContentType to the appropriate data type (image/jpeg for example)
 - Use the BinaryWrite method to stream the image binary data
 - End the response.

Here's some code I used that does this:
Code:
_oResponse.Clear()
_oResponse.ContentType = "image/jpeg"
_oResponse.BinaryWrite(objStream.ToArray)
objStream.Close()
_oResponse.Flush()
_oResponse.End()
You'll have to populate objStream with the data from the record in the database.

-Peter
 
Old April 12th, 2007, 09:47 PM
Authorized User
 
Join Date: Apr 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 While your approach is technical feasible, it's practically problematic (as you are finding).

1) All that disk IO really hurts performance when you gain nothing from it (i.e. you are not putting the file on disk to save it permanently, just as a temporary storage).

2) Because of the performance issue previously mentioned, you are likely to get two users competing for that single file.

3) Using the file system in a web application has it's own set of problems. You have to fight with permissions issues when you deploy such an application.

You should be able to take the file stream from the upload event and save it directly into the database without going through the file system at all. This will be significantly more efficient. Presuming that you have some identifier for the row that contains the image, you can uniquely identify it.

To retrieve the image, you can create a page or HttpHandler to process an image request. Instead of given a URL like: "/myapp/images/img.jpg", you give one that looks like this: "/myapp/getimage.aspx?imageID=123456". When the page runs, you do these steps:

 - Clear the response buffer (so there isn't anything emitted to start)
 - Change the Response.ContentType to the appropriate data type (image/jpeg for example)
 - Use the BinaryWrite method to stream the image binary data
 - End the response.

Here's some code I used that does this:
Code:
_oResponse.Clear()
_oResponse.ContentType = "image/jpeg"
_oResponse.BinaryWrite(objStream.ToArray)
objStream.Close()
_oResponse.Flush()
_oResponse.End()
You'll have to populate objStream with the data from the record in the database.

-Peter


----------------------------

hi friend,
thanx for the answer.,
its fine while saving image into the database,
i got your point; about saving the images.
but the problem is while retriving the images.,

what to do for retriving image.
as i have to display all the images in same page and in GridView control.

any idea for that....
thanx in advance...

 
Old April 12th, 2007, 10:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Just like with static images, you just end up with lots of <img> tags on the page that have src urls going to the image display page. Each image tag just references the page with the appropriate image ID. You construct the image tags in the repeating control.

<img src="/myapp/getimage.aspx?imageID=1" />
<img src="/myapp/getimage.aspx?imageID=2" />
<img src="/myapp/getimage.aspx?imageID=3" />
<img src="/myapp/getimage.aspx?imageID=4" />
<img src="/myapp/getimage.aspx?imageID=5" />
<img src="/myapp/getimage.aspx?imageID=6" />

and so on. Each of these will render a different image based on the imageID passed to it.

-Peter
 
Old April 13th, 2007, 12:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi kaushalparik,

In additional to what Peter said, you may want to read this:

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=414

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old April 13th, 2007, 01:17 AM
Authorized User
 
Join Date: Apr 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by planoie
 Just like with static images, you just end up with lots of <img> tags on the page that have src urls going to the image display page. Each image tag just references the page with the appropriate image ID. You construct the image tags in the repeating control.

<img src="/myapp/getimage.aspx?imageID=1" />
<img src="/myapp/getimage.aspx?imageID=2" />
<img src="/myapp/getimage.aspx?imageID=3" />
<img src="/myapp/getimage.aspx?imageID=4" />
<img src="/myapp/getimage.aspx?imageID=5" />
<img src="/myapp/getimage.aspx?imageID=6" />

and so on. Each of these will render a different image based on the imageID passed to it.

-Peter

im working with Image server Control... not <IMG> tag

 
Old April 13th, 2007, 01:36 AM
Registered User
 
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ripplecreations
Default

Replace the Image server controls property ImageURL with the HTTPHandler URL

<img src="/myapp/getimage.aspx?imageID=6" />

<asp:Image id="Image1" runat="server"
           AlternateText="Image text"
           ImageAlign="left"
           ImageUrl="/myapp/getimage.aspx?imageID=6"/>

OR

C# Code
Image1.ImageURL = "/myapp/getimage.aspx?imageID=6";


RippleCreations.com
 
Old April 13th, 2007, 08:50 PM
Authorized User
 
Join Date: Apr 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by ripplecreations
 Replace the Image server controls property ImageURL with the HTTPHandler URL

<img src="/myapp/getimage.aspx?imageID=6" />

<asp:Image id="Image1" runat="server"
           AlternateText="Image text"
           ImageAlign="left"
           ImageUrl="/myapp/getimage.aspx?imageID=6"/>

OR

C# Code
Image1.ImageURL = "/myapp/getimage.aspx?imageID=6";


RippleCreations.com
hi friend.,
as im totally novice to asp.net
can u bring me detailed/clear code to retrive image from database. so that i can view newly upload image instead of previous one.
i gone through on this issue for a long time.
but still not succeeded.
pls help me....
thankx

 
Old April 17th, 2007, 01:23 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did you read the article I linked to? I describes exactly what you want.

If that doesn't help, can you explain the problem in more detail?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old April 18th, 2007, 03:03 AM
Authorized User
 
Join Date: Apr 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by ripplecreations
 Replace the Image server controls property ImageURL with the HTTPHandler URL

<img src="/myapp/getimage.aspx?imageID=6" />

<asp:Image id="Image1" runat="server"
           AlternateText="Image text"
           ImageAlign="left"
           ImageUrl="/myapp/getimage.aspx?imageID=6"/>

OR

C# Code
Image1.ImageURL = "/myapp/getimage.aspx?imageID=6";


RippleCreations.com

Dear Friend...
the solution works for me...
its great..
thanks for help..






Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading Image to Image Control using JavaScript ctranjith General .NET 1 May 28th, 2013 05:43 AM
How to get the id of an image control jasdeephere ASP.NET 1.0 and 1.1 Professional 3 January 30th, 2007 09:06 AM
Barcode Image Control Zaff Access VBA 2 October 31st, 2006 07:00 PM
image control paulevision Dreamweaver (all versions) 0 November 18th, 2004 05:45 PM
Image Control edcaru Access 3 June 22nd, 2004 06:41 AM





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