How to Retrieving doc/pdf/xls files in SQL Server?

rudba

Member
Joined
Jan 15, 2009
Messages
5
Programming Experience
Beginner
Hello guy,

I have data on sql server 2005. Data are store on biary format.
How to retriev thoes data ino oc, pdf, xls forat?
 
Here's an example I wrote awhile back to test this. DocData is my blob and DocName is a varchar column containing the name of the document.

VB.NET:
	Private Sub SqlBlob2File(ByVal DocName As String)

		Dim cn As New SqlConnection(My.Settings.DocStoreConnectionString.ToString())
		Dim cmd As New SqlCommand("Select DocData From Documents WHERE DocName = @DocName", cn)

		cmd.Parameters.AddWithValue("@DocName", DocName)

		cn.Open()

		Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
			If dr.Read() Then
				Dim fs As IO.FileStream = New IO.FileStream(IO.Path.Combine(Me.FolderBrowserDialog1.SelectedPath, DocName), IO.FileMode.Create)
				Dim b() As Byte = dr.Item("DocData")
				fs.Write(b, 0, b.Length)
				fs.Close()
			End If
		End Using 'dr

		cn.Close()

	End Sub
 
Back
Top