Generic Procedure to open a file in default application using WPF

jaksel

Member
Joined
Sep 3, 2008
Messages
9
Programming Experience
Beginner
Open default Browser in WPF Application

I am creating a WPF application in VB.NET. I have a text box that contains a URL of a local HTML file such as C:\a\MyFile.html
I would like to open this file in the default browser when the use clicks a button on my WPF.... Here is what I have for my click event on the button:

dim aBrowser as New WebBrowser
aBrowser.Navigate(txtURL.text)
aBrowser.Show()


It returns an error code of 0.

Suggestions please.

Jim
 
Given a string representing the complete path to a file name strFileName = "c:\blah\blah\blah\myFile.xxx"
What is the general procedure to open this file in its default application?

Here is what works for office files like Excel, Word, PowerPoint, Project...

Dim xlApp As New Excel.Application 'PowerPoint.Application (or) Word.Application .... etc.
xlApp.Visible = True
xlApp.Workbooks.Open(txtFileName.Text)

But what about files like PDFs or HTML?
Suggestions welcomed
 
To further John's answer, simply run the target file (in your case the HTML or PDF file), and let Windows figure out what application to open from the registered MIME types. If you need a bit more control specifically in the case of a web browser, you can create an instance of IE in code and pass it parameters directly. The downside is that you cannot guarantee the user's preferred browser is in fact IE.
 
Back
Top