Results 1 to 4 of 4

Thread: visual studio 2017 how can i store a pdf document in sql server?

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    visual studio 2017 how can i store a pdf document in sql server?

    hey,
    i know there is a way to store pdf document in sql server i just dont know the method.
    i need the customer to download this file from the server.
    this file will be stored in a host through api.
    is there somebody that did this before?
    any help will be appreciated.
    salsa 31
    Last edited by salsa31; Jun 3rd, 2021 at 07:46 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: visual studio 2017 how can i store a pdf document in sql server?

    You need to get the file contents as a Byte array and then you save the data to the database in exactly the same way as you do any other data, using a varbinary column. How you get that Byte array depends on exactly what you're starting with. If you have a stream of some sort then you get the binary data out like you would any other stream. If you have a file then you can call File.ReadAllBytes. Etc.

  3. #3
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,048

    Re: visual studio 2017 how can i store a pdf document in sql server?

    to get the file something along the lines

    "varFilePath" is for the File you want
    Code:
     Dim file() As Byte
            Using stream = New FileStream(varFilePath, FileMode.Open, FileAccess.Read)
                Using reader = New BinaryReader(stream)
                    file = reader.ReadBytes(CInt(stream.Length))
                End Using
            End Using
    now pass "File" to the Database
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: visual studio 2017 how can i store a pdf document in sql server?

    Quote Originally Posted by ChrisE View Post
    to get the file something along the lines

    "varFilePath" is for the File you want
    Code:
     Dim file() As Byte
            Using stream = New FileStream(varFilePath, FileMode.Open, FileAccess.Read)
                Using reader = New BinaryReader(stream)
                    file = reader.ReadBytes(CInt(stream.Length))
                End Using
            End Using
    now pass "File" to the Database
    Why not just call File.ReadAllBytes?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width