Private Sub lpSaveDocuments()
Dim dsDocuments As DataSet
Dim dsDoc As DataSet
Dim intRowCnt As Integer
Dim strSql As String = ""
Dim strsqlDoc As String = ""
Dim strFileName As String = ""
Dim strDirPath As String = ""
Dim strFilePath As String = ""
strSql = <Outer SQL if needed>
dsDocuments = GetMyimagesFromDB()
'GetMyimagesFromDB is a function that returns a dataset of images,image name ...etc
Try
If Not (dsDocuments Is Nothing OrElse dsDocuments.Tables.Count = 0 OrElse dsDocuments.Tables(0).Rows.Count < 1) Then
'Open & Save Doc
For intRowCnt = 0 To dsDocuments.Tables(0).Rows.Count - 1
strFileName = <File Name, It could be from database if present>
strFilePath = ""
Dim arrByteData() As Byte
strDirPath = <Path to the Directory where extracted file is to be saved>
strsqlDoc = <SQL for selecting the binary field>
dsDoc = <Open the dataset>
If Not (dsDoc Is Nothing OrElse dsDoc.Tables.Count = 0 OrElse _
dsDoc.Tables(0).Rows.Count < 1) Then
arrByteData = dsDoc.Tables(0).Rows(0)("<Binary field name>")
strFilePath = String.Concat(strDirPath, strFileName)
Dim fs As System.IO.FileStream = _
New System.IO.FileStream(strFilePath, IO.FileMode.CreateNew, IO.FileAccess.ReadWrite)
Dim bw As System.IO.BinaryWriter = New System.IO.BinaryWriter(fs)
bw.Write(arrByteData)
bw.Flush()
bw.Close()
fs.Close()
fs.Dispose()
End If
If Not (dsDoc Is Nothing) Then
dsDoc.Dispose()
End If
Next
End If
If Not (dsDocuments Is Nothing) Then
dsDocuments.Dispose()
End If
Catch ex As Exception
End Try
End Sub