Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,302 members, 7,957,764 topics. Date: Tuesday, 24 September 2024 at 07:35 PM |
Nairaland Forum / Science/Technology / Programming / Inserting And Retrieving Images To/From Database In ASP.NET (6521 Views)
C# - Capturing File Name From A FileUpload Control In Asp.net / Fingerprint Programming In ASP.NET / Appointment Scheduler In Asp (2) (3) (4)
Inserting And Retrieving Images To/From Database In ASP.NET by chinesedoll(f): 10:49pm On Apr 21, 2006 |
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? |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by Seun(m): 1:05am On Apr 22, 2006 |
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. |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by Cactus(m): 1:08am On Apr 23, 2006 |
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/. |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by smartsoft(m): 12:44am On Apr 26, 2006 |
Hay @ruky do you Programm ?? or do you do database 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 |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by chinesedoll(f): 3:37pm On May 08, 2006 |
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 ur no or give my a call so we could talk. |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by naijaguru(m): 8:29pm On May 08, 2006 |
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 . |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by Zahymaka(m): 12:52am On May 09, 2006 |
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 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]. |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by Nobody: 6:42am On May 12, 2006 |
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#. |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by chinesedoll(f): 5:01pm On May 17, 2006 |
thanks guys although am not finding it easy sha but with .net i thing the sky is going to be my starting point. Zahymaka: 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. |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by Zahymaka(m): 5:55pm On May 17, 2006 |
ruky_ivy, I was talking of most girls . 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). |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by turbo: 5:43pm On Sep 29, 2006 |
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 |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by IG: 7:51pm On Feb 27, 2007 |
Seun: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. |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by cocoon(m): 6:15pm On Mar 25, 2007 |
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 |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by ucard: 11:39am On Mar 26, 2007 |
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) |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by my2cents(m): 10:42am On Mar 28, 2007 |
all dis excitement over female programmer, make una no get wet dream o! LMAO |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by IG: 9:10pm On Sep 14, 2007 |
my2cents: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. |
Re: Inserting And Retrieving Images To/From Database In ASP.NET by Kobojunkie: 9:26pm On Sep 14, 2007 |
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 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 |
(1) (Reply)
How To Print All Records From A Datagridview In Vb.net / Who's Interested In Learning Python For Data Science (from Scratch) / Local Software Piracy (Otigba Boys) - The Way Forward
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 42 |