Viewing Files from SQL Filestream using Winforms Application

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi Guys,
I am trying to open files from my Filetable using SQL Filestream in my winforms application. At the moment I have succeded using the below method in my button click event. It seems rather longwinded and wanted to know if there is an easier way to open files stored in my Filetable as I am finding it difficult in getting rid of my temporary files with this approach etc.
Try
Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
Dim sTempFileName As String = Application.StartupPath & "" & Me.MyDocumentStoreBindingSource.Current("name")
Dim fs As New FileStream(Me.MyDocumentStoreBindingSource.Current("name"), FileMode.OpenOrCreate, FileAccess.Write)


Try

fs.Write(fileData, 0, fileData.Length)
fs.Flush()
fs.Close()


Dim thread As New Thread(
Sub()
Dim proc As Process = Process.Start(sTempFileName)
proc.WaitForExit()
File.Delete(sTempFileName)
End Sub
)
thread.Start()


Finally
If fs IsNot Nothing Then
fs.Dispose()
End If
End Try

Catch ex As Exception
End Try
How can I open the file as if I was accessing the file name directly i.e. Process.Start("C:DataMyDoc.pdf") if that makes sense. Any suggestions as to the best way to open the files from my application are truly welcome.

Thank you for your help in advance

View the full article
 
Back
Top