Storing images in SQL DB example code

Last post 10-17-2007, 8:24 AM by gibbitty. 8 replies.
Sort Posts: Previous Next
  •  05-30-2007, 9:55 PM 30259

    Storing images in SQL DB example code

    Does anyone have the example code to store the images in SQL written in VB.net? The current examples are only in C# and I have converted the code the best I can and it works until it comes time to upload an image. It is erroring out due to a sql reader already being open that needs to close, which I think could be handled correctly if the translated code were correct.
  •  05-30-2007, 10:03 PM 30260 in reply to 30259

    Re: Storing images in SQL DB example code

    never mind, i got it working.

  •  06-02-2007, 10:14 AM 30333 in reply to 30260

    Re: Storing images in SQL DB example code

    Do you think you can send me the VB  code that you created, I am new at this and use vb.net and am having problems converting the code, [email protected]
  •  06-04-2007, 10:23 AM 30353 in reply to 30333

    Re: Storing images in SQL DB example code

  •  06-13-2007, 2:58 PM 30689 in reply to 30259

    Re: Storing images in SQL DB example code

    What version of the Cute Editor are you using?

    I've seen some posts that suggest the example does not work for 5.2 or 6.0. I'm on 5.3 at the moment. I'd upgrade to 6 if I knew someone had successfully gotten the Cute Editor to work with the CustomFileProvider example.

  •  06-13-2007, 3:11 PM 30692 in reply to 30689

    Re: Storing images in SQL DB example code

    Eggcited,
     
    When you grade from version 5.3 you need to update the custom file provider project as well.
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  06-14-2007, 9:49 AM 30730 in reply to 30692

    Re: Storing images in SQL DB example code

    So... you're saying that the custom file provider does work for 6.0? I've seen posts to the contrary.

    I haven't started in on the custom file provider yet in any version. I'd like to upgrade to 6.0 and then implement it, but I need to know if it does work or not before I do.
  •  06-14-2007, 9:56 AM 30732 in reply to 30730

    Re: Storing images in SQL DB example code

  •  10-17-2007, 8:24 AM 34367 in reply to 30260

    Re: Storing images in SQL DB example code

    heres the code if anyone is interested.
     

    --On Page that holds the Editor--
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Editor1.Setting("CuteEditorFileStorageType") = GetType(SqlFileStorage).AssemblyQualifiedName
            Editor1.Setting("DownFile") = ResolveUrl("DownFile.Aspx")
            Editor1.SetSecurityGalleryPath("/")

    End Sub

    --Downfile.aspx codebehind--
    Imports System
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Web
    Imports System.Web.SessionState
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls
    Imports System.Data.SqlClient
    Imports System.Configuration

    Partial Public Class DownFile
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        End Sub
        Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
            Dim dt As DateTime
            Dim filename As String
            Dim filesize As Integer
            Dim filedata As Byte()
            ' Using
            Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnection").ConnectionString)
            Try
                conn.Open()
                Dim fileid As Integer = Integer.Parse(Request.QueryString("fileid"))
                ' Using
                Dim cmd As SqlCommand = New SqlCommand("select * from fsitems where id=@p0", conn)
                Try
                    cmd.Parameters.AddWithValue("@p0", fileid)
                    ' Using
                    Dim reader As SqlDataReader = cmd.ExecuteReader
                    Try
                        If Not reader.Read Then
                            Throw (New HttpException(404, " File Not Found "))
                        End If
                        dt = reader.GetDateTime(reader.GetOrdinal("createdt"))
                        filename = reader.GetString(reader.GetOrdinal("filename"))
                        filesize = reader.GetInt32(reader.GetOrdinal("filesize"))
                        filedata = CType(reader("filedata"), Byte())
                    Finally
                        CType(reader, IDisposable).Dispose()
                    End Try
                Finally
                    CType(cmd, IDisposable).Dispose()
                End Try
            Finally
                CType(conn, IDisposable).Dispose()
            End Try
            Response.ClearHeaders()
            Response.AddHeader("Content-Length", filesize.ToString)
            Response.BinaryWrite(filedata)
            Response.End()
        End Sub


    End Class

View as RSS news feed in XML