Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Images, Databinding and Linq

Images, Databinding and Linq

Scheduled Pinned Locked Moved LINQ
databasequestioncsharpcsslinq
5 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JimBob SquarePants
    wrote on last edited by
    #1

    Alright guys, here's a question for you....... I am currently working on a web project using linq to Sql and I'm having trouble saving and restoring images from my database. I have a DisplayView nested within one of my views in a MultiView. On this view I want to be able to display and edit up to four images. Now I know that using a FileUpload and a Button I can convert the PostedFile.ContentLength attribute of the FileUpload to a Byte and save it to my database...... I don't want to directly do this though. What I want is to use the fileupload to populate my image (dependent on whether the checkbox/grid is checked) with the imageurl then perform the save later with the standerd linq update for my entire record. Should I be using a GridView with each grid bound to each image instead of a details view with an image?? Can I convert from an imageurl to System.Data.Linq.Binary?? I've googled the crap out of this (That's how I found out about System.Data.Linq.Binary), but I'm getting nowhere. I've a funny feeling that I'm going in entirely the wrong direction and that this is much easier than I think. What would you do? :confused: Many, Many Thanks in advance.

    JimBob SquarePants --------------------------------------------------------------------------------------- A computer once beat me at chess, but it was no match for me at kick boxing. -- Emo Philips --

    J J 2 Replies Last reply
    0
    • J JimBob SquarePants

      Alright guys, here's a question for you....... I am currently working on a web project using linq to Sql and I'm having trouble saving and restoring images from my database. I have a DisplayView nested within one of my views in a MultiView. On this view I want to be able to display and edit up to four images. Now I know that using a FileUpload and a Button I can convert the PostedFile.ContentLength attribute of the FileUpload to a Byte and save it to my database...... I don't want to directly do this though. What I want is to use the fileupload to populate my image (dependent on whether the checkbox/grid is checked) with the imageurl then perform the save later with the standerd linq update for my entire record. Should I be using a GridView with each grid bound to each image instead of a details view with an image?? Can I convert from an imageurl to System.Data.Linq.Binary?? I've googled the crap out of this (That's how I found out about System.Data.Linq.Binary), but I'm getting nowhere. I've a funny feeling that I'm going in entirely the wrong direction and that this is much easier than I think. What would you do? :confused: Many, Many Thanks in advance.

      JimBob SquarePants --------------------------------------------------------------------------------------- A computer once beat me at chess, but it was no match for me at kick boxing. -- Emo Philips --

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Well, I'm not an ASP.NET guy so I might not be able to help a whole lot, given you asked some ASP.NET questions, such as whether you should be using a GridView with image binding. Regarding the LINQ-specific parts of your question, have you seen Uploading an image or file using LINQ[^]? You asked can you convert an imageurl to System.Data.Linq.Binary. I must not understand - it's not as simple as grabbing the image from the URL, writing the bytes to a Linq.Binary?

      J 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Well, I'm not an ASP.NET guy so I might not be able to help a whole lot, given you asked some ASP.NET questions, such as whether you should be using a GridView with image binding. Regarding the LINQ-specific parts of your question, have you seen Uploading an image or file using LINQ[^]? You asked can you convert an imageurl to System.Data.Linq.Binary. I must not understand - it's not as simple as grabbing the image from the URL, writing the bytes to a Linq.Binary?

        J Offline
        J Offline
        JimBob SquarePants
        wrote on last edited by
        #3

        Easy for you maybe. ;P Yeah I looked at Rocks thoughts. It was getting the info back that was the biggest problem. Something you said in your reply just got my brain working though. I've just Googled (I hate that word)"Linq.Binary to Byte" and found this. http://weblogs.asp.net/bryansampica/archive/2007/11/29/converting-sql-linq-binary-to-byte.aspx[^] This seems to be the answer I was looking for.... Wish me luck! Thanks for your reply.

        JimBob SquarePants --------------------------------------------------------------------------------------- A computer once beat me at chess, but it was no match for me at kick boxing. -- Emo Philips --

        1 Reply Last reply
        0
        • J JimBob SquarePants

          Alright guys, here's a question for you....... I am currently working on a web project using linq to Sql and I'm having trouble saving and restoring images from my database. I have a DisplayView nested within one of my views in a MultiView. On this view I want to be able to display and edit up to four images. Now I know that using a FileUpload and a Button I can convert the PostedFile.ContentLength attribute of the FileUpload to a Byte and save it to my database...... I don't want to directly do this though. What I want is to use the fileupload to populate my image (dependent on whether the checkbox/grid is checked) with the imageurl then perform the save later with the standerd linq update for my entire record. Should I be using a GridView with each grid bound to each image instead of a details view with an image?? Can I convert from an imageurl to System.Data.Linq.Binary?? I've googled the crap out of this (That's how I found out about System.Data.Linq.Binary), but I'm getting nowhere. I've a funny feeling that I'm going in entirely the wrong direction and that this is much easier than I think. What would you do? :confused: Many, Many Thanks in advance.

          JimBob SquarePants --------------------------------------------------------------------------------------- A computer once beat me at chess, but it was no match for me at kick boxing. -- Emo Philips --

          J Offline
          J Offline
          JimBob SquarePants
          wrote on last edited by
          #4

          Does anyone know how to test if the result is false in this situation? I'm trying "If result is Nothing Then" but it's not working.:confused: Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest If Not String.IsNullOrEmpty(HttpContext.Current.Request.QueryString("imageID")) Then Dim imageID = HttpContext.Current.Request.QueryString("imageID") Dim db As New AuctionsDataContext Dim result = From img In db.Images _ Where img.imageID = imageID _ Select img.image HttpContext.Current.Response.BinaryWrite(CType(result.First.ToArray, Byte())) context.Response.End() End If End Sub

          JimBob SquarePants --------------------------------------------------------------------------------------- A computer once beat me at chess, but it was no match for me at kick boxing. -- Emo Philips --

          J 1 Reply Last reply
          0
          • J JimBob SquarePants

            Does anyone know how to test if the result is false in this situation? I'm trying "If result is Nothing Then" but it's not working.:confused: Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest If Not String.IsNullOrEmpty(HttpContext.Current.Request.QueryString("imageID")) Then Dim imageID = HttpContext.Current.Request.QueryString("imageID") Dim db As New AuctionsDataContext Dim result = From img In db.Images _ Where img.imageID = imageID _ Select img.image HttpContext.Current.Response.BinaryWrite(CType(result.First.ToArray, Byte())) context.Response.End() End If End Sub

            JimBob SquarePants --------------------------------------------------------------------------------------- A computer once beat me at chess, but it was no match for me at kick boxing. -- Emo Philips --

            J Offline
            J Offline
            JimBob SquarePants
            wrote on last edited by
            #5

            Hi guys, I thought i'd post my solution to the question I asked the other day. I know linq is still pretty new to a lot of us and there isn't that much documentation out there regarding working with images. What my code does is looks via a httphandler on my database for an image in column image1 in the tblImages table. If there is no result for the query then the code looks for an image stored locally in an /Images/ folder and places an alternative image. It seems to be lightning fast on my local machine though i've yet to try it online. Anyhoo, Apologies for the formatting, VS to Notepad to CP doesn't look nice......I hope this helps someone out there. ;) The http handler ---------------------------------------------------------------------- Public Class PhotoHandler Implements System.Web.IHttpHandler Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest If Not String.IsNullOrEmpty(HttpContext.Current.Request.QueryString("ImageID")) Then Dim Name = HttpContext.Current.Request.QueryString("ImageID") Try Dim result = GetPhoto(ImageID) If result IsNot Nothing Then HttpContext.Current.Response.BinaryWrite(CType(result.ToArray, Byte())) context.Response.End() Else Dim photo As Stream = PhotoManager.GetPhoto() Dim buffersize As Integer = (1024 * 16) Dim buffer() As Byte = New Byte((buffersize) - 1) {} Dim count As Integer = photo.Read(buffer, 0, buffersize) Do While (count > 0) context.Response.OutputStream.Write(buffer, 0, count) count = photo.Read(buffer, 0, buffersize) Loop End If Catch ex As Exception End Try End If End Sub ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return True End Get End Property End Class ---------------------------------------------------------------------- My Functions ---------------------------------------------------------------------- Imports System.IO Public Class PhotoManager Public Overloads Shared Function GetPhoto() As Stream Dim ptpath As String = HttpContext.Current.Server.MapPath("~/Image

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups