Groups | Blog | Home
all groups > vb.net > april 2004 >

vb.net : File Type associated program selector



Brian Henry
4/20/2004 10:41:39 PM
Hello,

I have been working executeing files a user selects in a database, my
problem is that the file type may or may not be associated in the end users
system. How can I go about, when the user executes a file, if the file does
not have an associated application with it, show the window in windows that
asks the user what they would like to open it with? (The select program from
list window) thanks!


Brian Henry
4/21/2004 7:10:39 AM
I'm reatrieveing the image data from SQL Server storeing it in a file then
trying to do a start process on it. I thin Herfried might of answered the
question for me :)

[quoted text, click to view]

Cor Ligthert
4/21/2004 9:35:29 AM
Hi Brian,

I do not know if I am the only one who does not understand it.
Your talking about executing files in a database.
I thought you only could retrieve a file from a database.

However maybe I do not know something about processing a datatype in a
database, I am curious to know which datatype I than have to use.

Can you explain it a little bit more?

Cor

hirf-spam-me-here NO[at]SPAM gmx.at
4/21/2004 9:57:15 AM
* "Brian Henry" <brianiupmsdn@newsgroups.nospam> scripsit:
[quoted text, click to view]

Set up a 'ProcessStartInfo', set its 'ErrorDialog' property to 'True'
and pass it to 'Process.Start'.

--
Herfried K. Wagner [MVP]
Brian Henry
4/21/2004 12:43:43 PM
it's not a picture image, but an image data type in SQL server, the actual
file could be anything from a picture or text document to a 100MB data
file...

[quoted text, click to view]

Cor Ligthert
4/21/2004 2:58:16 PM
Hi Brian,

Did you ever saw this sample of me, with that there is no saving to disk
needed?
The XML file is just to imitate a dataset from a database or a datareader.

Cor


Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType =
System.Type.GetType("System.Byte[]")
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema)
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.FileName)
End If
abyt = CType(ds.Tables(0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
///

Cor Ligthert
4/21/2004 7:19:48 PM
That is this sample for Brian, however the database is an XML dataset, but
that is the same for this.

It can even be a program, however keep in mind that it can become very slow
when you load huge files in your database.

Cor

[quoted text, click to view]

AddThis Social Bookmark Button