Inserting And Retrieving Images To/From Database In ASP.NET

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 24, 2009, 12:26 AM
431574 members and 298587 Topics
Latest Member: lok1978
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Inserting And Retrieving Images To/From Database In ASP.NET
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Inserting And Retrieving Images To/From Database In ASP.NET  (Read 2353 views)
chinesedoll (f)
Inserting And Retrieving Images To/From Database In ASP.NET
« on: April 21, 2006, 10:49 PM »

Programmers in the house, please can anybody give me the code with which I could use in inserting and retrieving an image from the database in ASP.NET?
Seun (m)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #1 on: April 22, 2006, 01:05 AM »

You shouldn't store images in a database.  You should store them in the filesystem and refer to the filenames in your database.  That is easier and also more efficient.  Cheers!

If you must store images in a database, use BLOB columns.
Cactus (m)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #2 on: April 23, 2006, 01:08 AM »

why do u guys use asp/asp.net, though i am very good with building application in asp.net its very problematic and kinda difficult to debug.

I actually fell sick programming in asp.net for about 1week. twasnt fun/.
smartsoft (m)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #3 on: April 26, 2006, 12:44 AM »

Hay @ruky do you  Programm ?? or do you do database huh Huh i would like to know yah ooo because i do know you stay @ Ipaja area.  Well ASP.NET really sucks for me don't know why i use PHP/MySql
chinesedoll (f)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #4 on: May 08, 2006, 03:37 PM »

Smartsoft, sure i program but i wld love to know how to program
im PHP/MYSQL.
If u say u are very good at it just send your no or give my a call so we
could talk.
naijaguru (m)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #5 on: May 08, 2006, 08:29 PM »

Ok Ruky,

I hardly come across programming girls in naija! I thot all they knew was lipsticks (apology) I would holla ya from my email and we can talk.

PHP
MYSQL
JAVASCRIPT
JAVA (in view)

www.codixel.com (under construction)

Damilare .

Zahymaka (m)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #6 on: May 09, 2006, 12:52 AM »

naijaguru you just hit the nail on the head! I always said something similar to what you said but mine goes:

Most girls are not interested in programming because they prefer to talk about lipstick and lingerie  Grin

ruky_ivy, I've done some image work with Asp.NET before. I'll hunt through my code and post it on here -- it uses a database like you intended. What exactly do you want to do -- use it in a datagrid or repeater?

Just know that you'll need to make use of the PictureBox control [asp:Image].
Gridlock (m)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #7 on: May 12, 2006, 06:42 AM »

Did i hear the words "female programmer" ?? Good heavens! U are welcome, sure u'll get all the support u need. But I don't do ASP.NET (yet), only technology i know now is C#.
chinesedoll (f)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #8 on: May 17, 2006, 05:01 PM »

thanks guys although am not finding it easy sha
but with .net i thing the sky is going to be my starting point.
Quote from: Zahymaka on May 09, 2006, 12:52 AM
naijaguru you just hit the nail on the head! I always said something similar to what you said but mine goes:

Most girls are not interested in programming because they prefer to talk about lipstick and lingerie  Grin

ruky_ivy, I've done some image work with Asp.NET before. I'll hunt through my code and post it on here -- it uses a database like you intended. What exactly do you want to do -- use it in a datagrid or repeater?

Just know that you'll need to make use of the PictureBox control [asp:Image].

i am trying to build a web application just like hi5
what i just want to know is how to be able to store and retreive
images from the database because am really confused.
Some gurus said i said i should just retreive into a label
how possible is that?


One more thing there are a lot of female programers in my sch Aptech
so u guys dont think its only lipsticks we've got in our heads we
are also up to the task.
Zahymaka (m)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #9 on: May 17, 2006, 05:55 PM »

ruky_ivy, I was talking of most girls  Wink. I think I'm not the only programmer who gets excited about seeing a female programmer -- and a pretty one at that.

I seem to have left the code I'm talking about back in Nigeria. These articles should be helpful but if you have problems you can buzz me on Yahoo Messenger. Don't worry if it indicates 'offline' -- I'm always online, although I might not be around.

Here are the links:

1. If you want to display the images inline in your page

2. For displaying in a datagrid or repeater try this and this. I'd recommend the second one if you're using Visual Web Developer (Asp.NET 2.0).
turbo
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #10 on: September 29, 2006, 05:43 PM »

Zahymaka, am kind of new to this website and still trying to find my way around. pls how do deploy an asp.net application using sql server including the database files and often times when i try to save images to a folder it gives me errors like"access to filepath c:\, \, \ is denied" is it because of ntfs file system or what . thanks
IG
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #11 on: February 27, 2007, 07:51 PM »

 
Quote from: Seun on April 22, 2006, 01:05 AM
You shouldn't store images in a database.  You should store them in the filesystem and refer to the filenames in your database.  That is easier and also more efficient.
I am of the view that you keep your images along with other data in the database. Poeple keep images in the filesystem simply because they find it difficult to put them in the database.

Although I don't program ASP.NET but I've done it in C# and VB.NET.

Create a BLOB column in the database where you will write the image.

The column expects a binary array so you have to convert your image to a series of bytes you can store in an array.

This is done as follows.

1- Use the image.Save method to save to a memory stream, make sure the you specify the image format to be raw.

2- Copy the memory stream to a byte array

3- Write the array to the column.

to read from the column back to an Image

1- Read the column into a byte array

2- Write the byte array into a memory stream

3- Use the Image.FromStream method to reconstruct back an Image object


I hope this will get you through, though no code snippets are provided.
cocoon
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #12 on: March 25, 2007, 06:15 PM »

its pretty easy inserting and retrieving  images in asp.net

For insertion

Using System.IO;

protected System.Web.UI.HtmlControls.HtmlInputFile ScannedDocument; //file dialog for inserting the image

BinaryReader rd;
rd=new BinaryReader(ScannedDocument.PostedFile.InputStream);
         byte[] img = rd.ReadBytes(ScannedDocument.PostedFile.ContentLength); // image to insert
         string docname=ScannedDocument.PostedFile.FileName.Substring(ScannedDocument.PostedFile.FileName.LastIndexOf(@"\")+1); // image name



ayo2000us@yahoo.com
         
ucard
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #13 on: March 26, 2007, 11:39 AM »

If you are using asp.net 2.0 or 3.0 and sql server 2005. You can use the fileupload server control to get the image from a file on the client. If the image is larger than 80KB, Read it in chunk and update the field on the server with the chunk. The data type for this field should be the varbinary or image sql datatype.

To retrieve this image for display, you have to create an ashx file which implements IHandler Interface. Store the image from the database in the ashx file and let the control that would display the image point to the ashx file as the image url.

Storing images on database gives more control over the management of those images, and enhances bulk update of the database. I recomend storage of images on the server.

NOTE:
If you want the code that would do the storage and retrieval of images on a database, you may patronise my components. I have a component that does that on sale. The present implementation is on dot Net framework 2.0 and sql server 2005.  It goes for $200.00.

You may reach me at:
Micro Solutions Building
11 Shasha Road, Akowonjo (Opposite Union bank)
Lagos State.
My direct line is 08066083333.

UCard
(a technology evolving from Nigeria)

my2cents (m)
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #14 on: March 28, 2007, 10:42 AM »

all dis excitement over female programmer, make  una no get wet dream o!  LMAO  Tongue
IG
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #15 on: September 14, 2007, 09:10 PM »

Quote from: my2cents on March 28, 2007, 10:42 AM
all this excitement over female programmer, make  una no get wet dream o!  LMAO  Tongue
I never knew one can get a wet dream by just discussing with a female on a forum. But since you fear getting
a wet dream, I recomend you see a doctor. Sorry we're only programmers, we can't help you on that.
Kobojunkie
Re: Inserting And Retrieving Images To/From Database In ASP.NET
« #16 on: September 14, 2007, 09:26 PM »

Below is sample code you can look at and take advantage of



Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSubmit.Click
        Dim temp As String = FileName.Value.ToString()

        Dim MyEvent As New Banner

        Dim RootPath As String = Banner.GetRootPath()
        Dim BeginDate As Date = CDate(Me.BeginDate.Text)
        Dim EndDate As Date = CDate(Me.EndDate.Text)
        Dim Title As String = EventTitle.Text()
        Dim LinkURL As String = Left(EventURL.Text(), 200)

        Dim Index As Integer = temp.LastIndexOf(".") + 1
        Dim Extension As String

        If Index <> 0 Then
            Extension = temp.Substring(Index, temp.Length() - Index)
        Else
            Extension = ""
        End If

        Dim MyEventID As Integer

        Try
            If FileName.PostedFile.ContentLength > 0 Then
                If FileName.PostedFile.ContentLength > 52428800 Then  '50MB * (1024^2) = 52428800
                    LblMessage.CssClass = "ErrorMessage"
                    LblMessage.Text = "File size can not exceed 50 megabytes."
                    Exit Sub
                End If

                MyEventID = MyEvent.CreateOrUpDateEvent(UserID, Title, Me.FileName.PostedFile.FileName, Extension, BeginDate, EndDate, LinkURL, SiteID)

                If MyEventID > 1 Then
                    If True Then
                        Try
                            FileName.PostedFile.SaveAs(RootPath & "\Media\Pending\BannerAds" & "\" & MyEventID & "." & Extension)
                        Catch ex As Exception
                            If Err.Number = 76 Then
                                MkDir(RootPath & "\Media\Pending\BannerAds" & "\")
                                FileName.PostedFile.SaveAs(RootPath & "\Media\Pending\BannerAds" & "\" & MyEventID & "." & Extension)
                            End If
                        End Try
                    Else
                        Try
                            FileName.PostedFile.SaveAs(RootPath & "\Media\BannerAds" & "\" & MyEventID & "." & Extension)
                        Catch ex As Exception
                            If Err.Number = 76 Then
                                MkDir(RootPath & "\Media\BannerAds" & "\")
                                FileName.PostedFile.SaveAs(RootPath & "\Media\BannerAds" & "\" & MyEventID & "." & Extension)
                            End If
                        End Try
                    End If
                ElseIf MyEventID = 1 Then
                    LblMessage.CssClass = "ErrorMessage"
                    LblMessage.Text = "Event with same name already exists. Please use another event name."
                    Exit Sub
                Else
                    LblMessage.CssClass = "ErrorMessage"
                    LblMessage.Text = "Unknown file upload error, please try again."
                    Exit Sub

                End If

            Else
                LblMessage.CssClass = "ErrorMessage"
                LblMessage.Text = "File does not exists or is zero bytes <br />in length, and can not be uploaded."
                Exit Sub
            End If

        Catch ex As Exception
            LblMessage.CssClass = "ErrorMessage"
            LblMessage.Text = ex.Message
            Exit Sub
        End Try

        LblMessage.CssClass = "SuccessMessage"
        LblMessage.Text = "File successfully uploaded. The <br/> event banner is available for preview."
        Exit Sub
    End Sub




KoboJunkie


 How Do I Create A Desktop Shortcut For My Application?  Post Your C#.net Questions Here  Final Year Project Topics, Pls.  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.