Solved

How to open file from SQL File Table using VB or c# .net

Posted on 2013-05-21
64
2,012 Views
Last Modified: 2013-05-23
Hi Guys,

How can I open a file from my SQL Filetable using VB or C# .net using its saved file type extension? I.e if the extension is .pdf I would like to open the filestream object in Adobe, if .xlsx in Excel etc.?

I am using a bound data set in my application and that opens images straight awat but not .pdf, xlsx, docx extensions etc.?

Thank you for your help in advance
0
Comment
Question by:databarracks
  • 37
  • 27
64 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39186574
just use Process.Start("filename").
windows will detect associate application to file extension.
0
 

Author Comment

by:databarracks
ID: 39186685
Hi,

Your method doesn't really work unfortunately. I am aware of the process.start approach however I have this in my code and nothing happens

        Try
            Process.Start(Me.MyDocumentStoreBindingSource.Current("name"))
        Catch
        End Try

Open in new window


Thank you for your help?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39186707
what is the value of Me.MyDocumentStoreBindingSource.Current("name")?
0
 

Author Comment

by:databarracks
ID: 39186714
The value is 'MyText.txt' it is simply the name safe name of the file. Therefore it doesn't know where to look for the file. The filetable has all the typical columns associated with SQL Filesteam as per my attached screenshot.
filetable-structure.png
0
 

Author Comment

by:databarracks
ID: 39186719
The table row looks like the attached screenshot if it helps. Thank you again for your help on this, I really appreciate it.
filetable-result.png
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39186735
where's the actual file exists?
0
 

Author Comment

by:databarracks
ID: 39186739
The file resides on the server that hosts the SQL database. Are you familiar with SQL Filestream/filetable structure and functionality?

I am trying to use the Filetable information to open the necessary files?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39186748
do u have file_stream column?
it contains the actual file stream, which u can use to save to a file and open it using the same method suggested.
0
 

Author Comment

by:databarracks
ID: 39186763
Yes I do have a file_stream column as per my screenshot. How would I go about doing that and can it be a temporary file or something because I don't want the users to have to save the file every time they open a file. This would lead to reduced disk space etc.?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39186770
u don't save it on your HD for good, u use System.IO.Path.GetTempFileName() and then cleanup the temp file.
otherwise how would u open the file?
0
 

Author Comment

by:databarracks
ID: 39186773
Ok I get it now, however would you be able to provide me with the sample code for performing this action and clean up etc?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39186914
it would be nice if you could increase the points to at least 300 cause it aint considers as an easy question
0
 

Author Comment

by:databarracks
ID: 39186920
Ok I have increased the points as requested
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39186979
dim filename as string = Me.MyDocumentStoreBindingSource.Current("name")
dim file_stream as byte() = Me.MyDocumentStoreBindingSource.Current("file_stream")
dim strPath as string = String.Format(@"{0}{1}{2}", Path.GetTempPath(), Path.GetFileNameWithoutExtension(filename), Path.GetExtension(filename));
dim objSqlFileStream as SqlFileStream  = new SqlFileStream(strPath , file_stream, FileAccess.Write)
objSqlFileStream.Write(buffer, 0, buffer.Length)
objSqlFileStream.Close()
dim p as Process = System.Diagnostics.Process.Start(strPath)
p.WaitForExit()
File.Delete(strPath);

Open in new window

0
 

Author Comment

by:databarracks
ID: 39186993
Hi sedgwick,

I have increased the points again as I can see that it was definitely not a simple answer. However I have pasted your code in my button click event and I am getting an error on

objSqlFileStream.Write(Buffer, 0, Buffer.Length)

Open in new window


It says
Error	2	'Buffer' is a type and cannot be used as an expression.	C:\Users\mark.couvaras\Documents\Visual Studio 2012\Projects\FileStorage\FileStorage\Form2.vb	44	32	FileStorage

Open in new window


And

Error	3	'Length' is not a member of 'System.Buffer'.	C:\Users\mark.couvaras\Documents\Visual Studio 2012\Projects\FileStorage\FileStorage\Form2.vb	44	43	FileStorage

Open in new window


Also on this part

Dim strPath As String = String.Format(@"{0}{1}{2}", Path.GetTempPath(), Path.GetFileNameWithoutExtension(filename), Path.GetExtension(filename))

Open in new window


I get an error

Error	1	Expression expected.	C:\Users\mark.couvaras\Documents\Visual Studio 2012\Projects\FileStorage\FileStorage\Form2.vb	41	47	FileStorage

Open in new window


by the '@"' section

I do appreciate your help on this
0
 

Author Comment

by:databarracks
ID: 39186994
I assume the last '@"' section error was a typo?
0
 

Author Comment

by:databarracks
ID: 39187025
I am also getting Path name is not valid here:

Dim objSqlFileStream As SqlFileStream = New SqlFileStream(strPath, file_stream, FileAccess.Write)

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187048
add this:
Import System.Data
Import System.Diagnostics
Import System.IO
Import System.Text

Open in new window

and i updated the code here:
dim filename as string = Me.MyDocumentStoreBindingSource.Current("name")
dim file_stream as byte() = Me.MyDocumentStoreBindingSource.Current("file_stream")
dim strPath as string = String.Format(@"{0}{1}{2}", Path.GetTempPath(), Path.GetFileNameWithoutExtension(filename), Path.GetExtension(filename));
dim objSqlFileStream as SqlFileStream  = new SqlFileStream(strPath , file_stream, FileAccess.Write)
objSqlFileStream.Write(file_stream, 0, file_stream.Length)
objSqlFileStream.Close()
dim p as Process = System.Diagnostics.Process.Start(strPath)
p.WaitForExit()
File.Delete(strPath);

Open in new window

0
 

Author Comment

by:databarracks
ID: 39187059
I actually just did the same code before you posted that and I ams till getting an error saying "The path name is not valid". When I message boxes the strPAth it looked fine to me? And also the @ symbol in
Import System.Data
Import System.Diagnostics
Import System.IO
Import System.Text

Open in new window

doesn't seem right is that a typo?

Yeah so it doesn't like the path name, any ideas why?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187069
i converted the coed from C# so i had some errors.
here's the code in vb.net:

        Dim filename As String = Me.MyDocumentStoreBindingSource.Current("name")
        Dim file_stream As Byte() = Me.MyDocumentStoreBindingSource.Current("file_stream")
        Dim strPath As String = String.Format("{0}{1}{2}", Path.GetTempPath(), Path.GetFileNameWithoutExtension(filename), Path.GetExtension(filename))
        Dim objSqlFileStream As SqlFileStream = New SqlFileStream(strPath, file_stream, FileAccess.Write)
        objSqlFileStream.Write(file_stream, 0, file_stream.Length)
        objSqlFileStream.Close()
        Dim p As Process = System.Diagnostics.Process.Start(strPath)
        p.WaitForExit()
        File.Delete(strPath)

Open in new window

0
 

Author Comment

by:databarracks
ID: 39187075
Hi again,

That is the code I have but I keeps breaking at this point as per attachment
Error.png
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187079
can u post the value of strPath ?
0
 

Author Comment

by:databarracks
ID: 39187083
It Is C:\Users\mark.couvaras\AppData\Local\Temp\MyText.txt
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187093
sorry my mistake:
        Dim filename As String = Me.MyDocumentStoreBindingSource.Current("name")
        Dim file_stream As Byte() = Me.MyDocumentStoreBindingSource.Current("file_stream")
        Dim strPath As String = String.Format("{0}{1}{2}", Path.GetTempPath(), Path.GetFileNameWithoutExtension(filename), Path.GetExtension(filename))
        Using sw As StreamWriter = New StreamWriter(strPath, FileAccess.Write)
            sw.Write(Encoding.ASCII.GetString(file_stream), file_stream.Length)
        End Using

        Dim p As Process = Process.Start(strPath)
        p.WaitForExit()
        File.Delete(strPath)

Open in new window

0
 

Author Comment

by:databarracks
ID: 39187110
Hi I am now getting an error on

 
sw.Write(Encoding.ASCII.GetString(file_stream), file_stream.Length)

Open in new window


Error is saying
Format exception unhandled
 'Input string was not in a correct format'?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187117
remove the file_stream.Length argument.
0
 

Author Comment

by:databarracks
ID: 39187132
Ok that makes an attempt to open the file now which is good. But when it starts to open the file I get errors such as

Could no complete this operation. The internal file signature is incorrect

Open in new window


And

Sorry we couldn't find your file.Is it possible it was moved, renamed or deleted?

Open in new window

0
 

Author Comment

by:databarracks
ID: 39187134
I have increased the points to maximum now, as this seems to be really difficult afterall :)
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187178
how do u bind the table to MyDocumentStoreBindingSource?
0
 

Author Comment

by:databarracks
ID: 39187197
I simply use the standard method of dropping the necessary table adapter, bindginsource and adapter manager onto my form I am also using a navigator to move through the records. Apologies I still don't understand what you are asking for as my table is called MyDocuementStore ?
0
 

Author Comment

by:databarracks
ID: 39187205
I don't understand if there is a better way of what I am trying to achieve. It seems so overcomplicated and I am simply trying to not use the varbinary(max) field type in my tables as the files mainly pdf's will be larger than 400KB.

Therefore it was recommended to use SQL FILESTREAM. I add my data easily using a SP and works perfectly. IT seems getting my application to open the damn file is twice as hard as inserting it??

You have been most helpful on this matter and wish I could be of more help but I seem to be losing hope :( as I am new to the whole SQL Filestream thing?
0
 

Author Comment

by:databarracks
ID: 39187280
Hi there,

I have managed to get it working using this method hooray:

        Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
        Dim sTempFileName As String = Application.StartupPath & "\" & Me.MyDocumentStoreBindingSource.Current("name")


        Using fs As New FileStream(Me.MyDocumentStoreBindingSource.Current("name"), FileMode.OpenOrCreate, FileAccess.Write)
            fs.Write(fileData, 0, fileData.Length)
            fs.Flush()
            fs.Close()
        End Using

        System.Diagnostics.Process.Start(Me.MyDocumentStoreBindingSource.Current("name"))

Open in new window


Do you see any drawbacks doing it this way?
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

Author Comment

by:databarracks
ID: 39187316
Actually just realised I would need to clean up or delete the document after it has been used? How would I do this?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187332
u need to wait till the process is exit and then delete it:
  dim proc as Process = Process.Start(Me.MyDocumentStoreBindingSource.Current("name"))
proc.WaitForExit()
File.Delete(Me.MyDocumentStoreBindingSource.Current("name"))

Open in new window

0
 

Author Comment

by:databarracks
ID: 39187343
Tried that already of which I end up getting the same errors that your code produced as in ID: 39187132
0
 

Author Comment

by:databarracks
ID: 39187377
Ok this is it I think. Changed my code to the below and everything works as expected. Opens the file accordingly, creates temporary file and once the file is closed deletes it straight away

        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 p As Process = System.Diagnostics.Process.Start(sTempFileName)
            p.WaitForExit()
            File.Delete(sTempFileName)
        Finally
            If fs IsNot Nothing Then
                fs.Dispose()
            End If
        End Try

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187443
my mistake, Me.MyDocumentStoreBindingSource.Current("name") is the file name only not the temporary file name (and path).
it should be
 
       Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
        Dim sTempFileName As String = Application.StartupPath & "\" & Me.MyDocumentStoreBindingSource.Current("name")


        Using fs As New FileStream(Me.MyDocumentStoreBindingSource.Current("name"), FileMode.OpenOrCreate, FileAccess.Write)
            fs.Write(fileData, 0, fileData.Length)
            fs.Flush()
            fs.Close()
        End Using

dim proc as Process = Process.Start(sTempFileName)
proc.WaitForExit()
File.Delete()

Open in new window


the problem with this code is the proc.WaitForExit() blocks the main thread from continue, so basically if you open the file on notepad, the application is stuck till user closes the notepad instance.
to avoid this, u wanna open it asynchronously.
0
 

Author Comment

by:databarracks
ID: 39187460
You are right, dammit I though we had it for a second :( How would I be able to open it asynchronously??
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187463
something like:
     
  Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
        Dim sTempFileName As String = Application.StartupPath & "\" & Me.MyDocumentStoreBindingSource.Current("name")


        Using fs As New FileStream(Me.MyDocumentStoreBindingSource.Current("name"), FileMode.OpenOrCreate, FileAccess.Write)
            fs.Write(fileData, 0, fileData.Length)
            fs.Flush()
            fs.Close()
        End Using

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

Open in new window


since the implementation is when user click a button, u wanna get the UI thread back and not wait till user closes process which might take a while.
0
 

Author Comment

by:databarracks
ID: 39187547
I think you have nailed it. I have tested your code and it opens the file without freezing the application UI and also it still deletes the temp file when it is closes.

After a tough battle I think we have finally found the solution. Great effort by you sedgwick and unless you see any pitfalls doing it this way, I would gladly close the question and bestow you with all the praises? You have been truly excellent
0
 

Author Comment

by:databarracks
ID: 39187615
One thing I did notice if it isn't too much to ask is if the user closes the application before they close the document the file remains. Is there a way I can iterate through the files and delete anything that is temporary?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187662
if you close the application, the thread that runs the process which opens the file and wait for WaiForExit() is also terminated so the file won't be deleted.
if you will try to delete the file before exit the application you will get an exception the file is used by another process.
some applications such as notepad++ would open message box saying the "file doesn't exists anymore, do you want to keep it on the editor?".
you can run a script just before exit your application, which will detect when user close the opened file and then delete it, however, that won't guarantee that the user didn't save it by another name, so its kinda useless.
0
 

Author Comment

by:databarracks
ID: 39187668
Hmmm, it also seems as though I can't open more than one document of the same ext type as it says failure to open document. Basically if I open a pdf using your method then open another pdf it fails to open the second one.

The error doesn't come from the application but from the default viewer for the file like Word, excel or adobe reader??

I don't know why I was too hasty in thinking this was finished :(
0
 

Author Comment

by:databarracks
ID: 39187681
Ahhh this is so annoying, I can't believe there is no way to open theses SQL Fielstream files like you would any other varbinary max column.

Too many issues!!
0
 

Author Comment

by:databarracks
ID: 39187690
What about memorystream instead of Filestream?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187718
let me check
0
 

Author Comment

by:databarracks
ID: 39187724
If it helps I will not allow the users to save anything over 5MB of data as Memorystream would possibly suffer??
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39187787
did u make sure it's not the same file you try to open?
cause i managed to open multiple files (pdf, image, txt etc).
0
 

Author Comment

by:databarracks
ID: 39187806
I can open multiple docs if they aren't the same ext. I cannot open two docx's or two pdf's etc. One of each works fine though
0
 

Author Comment

by:databarracks
ID: 39188006
This method below obviously doesn't delete the temp files but allows me to open multiple documents of the same file type. How can we combine your threading code with this to make it complete

        Try


            Dim sfileName As String = Me.MyDocumentStoreBindingSource.Current("name")
            Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
            Dim sTempFileName As String = Application.StartupPath & "\" & sfileName

            Using fs As New FileStream(sfileName, FileMode.OpenOrCreate, FileAccess.Write)
                fs.Write(fileData, 0, fileData.Length)
                fs.Flush()
                fs.Close()
            End Using

            Dim proc As Process = System.Diagnostics.Process.Start(sfileName)



        Catch ex As Exception

        End Try

Open in new window


It also doesn't freeze the UI, only caviate is that it can't delete the temp file?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39188558
The alternative is to add the location of each file the user opens to a queue.
When the application exits, go through the queue and delete them all.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39188565
Of the file is still locked by the process, skip to next one.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39189966
so what u wanna do is add the following:
Queue member which will store open files:
Private tempFilesQueue As Queue = New Queue

Open in new window

before start the process, enqueue the file:
tempFilesQueue.Enqueue(sfileName)
     Dim proc As Process = System.Diagnostics.Process.Start(sfileName)

Open in new window

and finally event handler to the form class (FormClosing):
 Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Dim fi As String
        While tempFilesQueue.Count > 0
            fi = tempFilesQueue.Dequeue
            If fi Is Nothing Then
                Exit While
            End If
            Try
                File.Delete(fi)
            Catch
            End Try
        End While
    End Sub

Open in new window

0
 

Author Comment

by:databarracks
ID: 39190095
Hi Sedgwick,

Thank you for your code.That sort of works here is the code I have
Private tempFilesQueue As Queue = New Queue
Try
            Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
            Dim filename As String = Me.MyDocumentStoreBindingSource.Current("name")
            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()
                  tempFilesQueue.Enqueue(sTempFileName)
                  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

Open in new window


Why can't it allow me to open twp word or pdf documents at the same time though?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39190152
get rid of the new thread code, use the tempFilesQueue code I've posted above.
i realized that the process being start (adobe for pdf, office for xls/docx, etc) effects WaitForExit of the process.
0
 

Author Comment

by:databarracks
ID: 39190161
Ok I have done that now as below but now the UI will freeze without your new thread code??

Private tempFilesQueue As Queue = New Queue
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click

        Try
            Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
            Dim filename As String = Me.MyDocumentStoreBindingSource.Current("name")
            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()



                tempFilesQueue.Enqueue(sTempFileName)
                Dim proc As Process = Process.Start(sTempFileName)
                proc.WaitForExit()
                File.Delete(sTempFileName)




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

        Catch ex As Exception
        End Try

    End Sub

Open in new window

0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39190180
if u use the queue, then u don't call proc.WaitForExit():

Private tempFilesQueue As Queue = New Queue
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click

        Try
            Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
            Dim filename As String = Me.MyDocumentStoreBindingSource.Current("name")
            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()



                tempFilesQueue.Enqueue(sTempFileName)
                Process.Start(sTempFileName)
          
            Finally
                If fs IsNot Nothing Then
                    fs.Dispose()
                End If
            End Try

        Catch ex As Exception
        End Try

    End Sub

 Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Dim fi As String
        While tempFilesQueue.Count > 0
            fi = tempFilesQueue.Dequeue
            If fi Is Nothing Then
                Exit While
            End If
            Try
                File.Delete(fi)
            Catch
            End Try
        End While
    End Sub

Open in new window

0
 

Author Comment

by:databarracks
ID: 39190196
Ahhh I see how it works now. Right it will do the job I guess, would you recommend that I use a proper temp path for:

Dim sTempFileName As String = Application.StartupPath & "\" & Me.MyDocumentStoreBindingSource.Current("name")

Open in new window


Because there will be moments where the user closes the application before the documents leaving it to not delete the temp file as the for closing event will not be running.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39190205
i'd use the temporary folder used by Path.GetTempPath():
Dim sTempFileName As String = Path.Combine(Path.GetTempPath(), Me.MyDocumentStoreBindingSource.Current("name"))

Open in new window

0
 

Author Comment

by:databarracks
ID: 39190231
Last issue (I am really sorry that I have spent a vast amount of your time on this)

Using the below code and accessing the proper temp folder in bold, the file doesn't open (no errors) and it doesn't create the file at all (no errors). Strange

 Try
            Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
            Dim filename As String = Me.MyDocumentStoreBindingSource.Current("name")
           [b] Dim sTempFileName As String = Path.Combine(Path.GetTempPath(), Me.MyDocumentStoreBindingSource.Current("name"))[/b]



            Dim fs As New FileStream(Me.MyDocumentStoreBindingSource.Current("name"), FileMode.OpenOrCreate, FileAccess.Write)


            Try

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


                tempFilesQueue.Enqueue(sTempFileName)
                Dim proc As Process = Process.Start(sTempFileName)





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

        Catch ex As Exception
        End Try

Open in new window

0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 500 total points
ID: 39190249
that should do the trick:
        Try
Dim fileData As Byte() = DirectCast(Me.MyDocumentStoreBindingSource.Current("file_stream"), Byte())
        Dim filename As String = Me.MyDocumentStoreBindingSource.Current("name")
        Dim sTempFileName As String = Path.Combine(Path.GetTempPath(), Me.MyDocumentStoreBindingSource.Current("name"))
 fs As New FileStream(sTempFileName, FileMode.OpenOrCreate, FileAccess.Write)
            fs.Write(fileData, 0, fileData.Length)
        End Using

        tempFilesQueue.Enqueue(sTempFileName)
        Process.Start(sTempFileName)
 Catch ex As Exception
        End Try

Open in new window

0
 

Author Comment

by:databarracks
ID: 39190283
That did do the trick sedgwick. Well I think that should conclude this epic question once and for all.

Just wanted to say that you have been most helpful, patient and very determined of which I cannot thank you enough for. I wish I could give you more points :) above the maximum because you have been outstanding.

Thank you very much and hope you enjoy the rest of your week.
0
 

Author Closing Comment

by:databarracks
ID: 39190285
Exceptional persistence from the expert along with patience like I have never seen before. Outstanding work and cannot say anything else as the expert was BRILLIANT!!
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39190286
u 2 mate, good luck.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now