Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF STATEMENT DEPENDING ON FILE EXTENTION?

Status
Not open for further replies.

dedo8816

Programmer
Oct 25, 2006
94
GB
Hi, I've created a browser for both internet and internal files on my intranet.

Basically i've included an "Open" button the explorer. When a user click open, an Open Dialog shows on screen. The user then selects a file to open, if its a file that the browser can handle it appears in the explorer window and if not.... This is where my problem is.

I can use: System.Diagnostics.Process.Start( _
OpenDialog.FileName)
to open everything, but i want this part of the code to only kick in if the file extention is .exe, other wise i want the broswer to try and handle it.

Is this possible? i.e.:

If file extension = .exe then
System.Diagnostics.Process.Start( _
OpenDialog.FileName)
else: open in browser
End If

Here is my code for the open button,

Private Sub BtnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOpen.Click
OpenDialog.ShowDialog()
Dim WB As CustomBrowser = Me.TabControl1.SelectedTab.Tag
WB.Navigate(OpenDialog.FileName)
On Error Resume Next

'System.Diagnostics.Process.Start( _
'OpenDialog.FileName)

End Sub
 

I think what you are looking for is:

if System.IO.Path.GetExtension(fileName) = "exe" then
doSomething
else
doSomethingElse
end if
 
Kliot's suggestion would be the best solution since its functionality matches what you're working with (a file extension). Note however that GetExtension() also returns the dot character and you may want to convert to lowercase.
Code:
If (System.IO.Path.GetExtension(fileName).ToLower = ".exe") Then

' Or an alternative (even though the above solution is better)

If (fileName.ToLower.EndWith(".exe")) Then
 
Hi guys,

thanks for your advise. Kliot's answer was great, worked a charm, Dave i like your advise on the case.

Is there anyway to expand the above code for my explorer to know what it can and cant handle by itself?, see below for a description of the programs function...

The program im creating is basically an all around explorer. Looks like Internet Explorer 7, looks like it just does the same stuff. The catch is that i've added that extra button that allows you to open basically any file from the explorer page.
That is, if you click on a word or excel doc (or any office file) it will open in the browser window, but if you click on an RDP or exe file etc, the browser will know to open it with its default program.

Just FYI, im not doing this for any reason other than im a novice with .net but i like to explore and learn. This is basically for my own learning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top