Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Viewing Files from SQL Filestream using Winforms Application

$
0
0

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:\Data\MyDoc.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


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>