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. Visual Basic
  4. how to download binary file from SQL SERVER to VB.NET

how to download binary file from SQL SERVER to VB.NET

Scheduled Pinned Locked Moved Visual Basic
csharpasp-netdatabasesql-server
2 Posts 2 Posters 0 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.
  • S Offline
    S Offline
    Syed Ali Raza
    wrote on last edited by
    #1

    Hi; I have a field of type 'image' in a table where files are stored in binary form. How would I download the file in its actual form in vb.net or ASP.NET. I use the ADODB.STREAM CLASS in Visual Basic 6 for this purpose but having problem in ASP.NET BYE

    A 1 Reply Last reply
    0
    • S Syed Ali Raza

      Hi; I have a field of type 'image' in a table where files are stored in binary form. How would I download the file in its actual form in vb.net or ASP.NET. I use the ADODB.STREAM CLASS in Visual Basic 6 for this purpose but having problem in ASP.NET BYE

      A Offline
      A Offline
      Alessandro
      wrote on last edited by
      #2

      Put this code in your page

                     Dim oAttachment As New GetAttach
                      Try
                          Me.Page.Response.Clear()
                          Me.Page.Response.ClearContent()
                          Me.Page.Response.ClearHeaders()
                          Response.ContentType = ""
                          Response.BinaryWrite(oAttachment.GetAttach())
                          Response.AddHeader("content-disposition", "attachment; filename=" + oAttachment.ATTACH\_NAME + "." + oAttachment.EXTENSION)
                          Me.Page.Response.End()
                      Catch ex As Exception
                          throw ex
                      End Try
      

      GetAttach Class to call getter stored procedure

      Public Function GetAttach(ByVal MyParameter As Integer)
      Dim docFileReader As SqlDataReader

          Try
      
              Dim Myadapter As New SqlDataAdapter
      
              Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
                  Using command As New SqlCommand("GetAttachment", connection)
                      command.CommandType = CommandType.StoredProcedure
                      command.Parameters.Add(New SqlParameter("@MY\_SP\_PARAMETER", MyParameter))
                      connection.Open()
                      docFileReader = command.ExecuteReader
                      docFileReader.Read()
                      EXTENSION = docFileReader.Item("EXTENSION").ToString
                      ATTACH\_NAME = docFileReader.Item("ATTACH\_NAME").ToString
                      WEIGHT = docFileReader.Item("WEIGHT").ToString
                      Dim FileData(docFileReader.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
                      docFileReader.GetBytes(0, 0, FileData, 0, FileData.Length)
                      docFileReader.Close()
      
                      Return FileData
      
                  End Using
              End Using
      
          Catch ex As Exception
              If IsNothing(docFileReader) = False Then
                  docFileReader.Close()
              End If
              Throw ex
          End Try
      
      End Function
      
      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