open html file in the browser, C#

On my webform, I have txtHtmlFileName, After I enter, for example abc.html in this text box and click on Open File button...

Question: What is the code to locate abc.html in C:\myFolder and display it in a new browser?
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
browse for file
Dim fd As OpenFileDialog = New OpenFileDialog() 
Dim strFileName As String

fd.Title = "Open File Dialog"
fd.InitialDirectory = "C:\MyFolder"
fd.Filter = "HTML files (*.html)|*.html|htm files (*.htm)|*.htm"fd.FilterIndex = 2
fd.RestoreDirectory = True

If fd.ShowDialog() = DialogResult.OK Then
   strFileName = fd.FileName
End If

Open in new window
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Hi David,

Is your solution applicable to also?

käµfm³d 👽Commented:
No, David's code is not applicable to the web. Alas, you have no way to browser a user's file system. That task is left to the user. The most you can do is present them with an "open file" dialog and let them do the searching for you. The only ways around this security feature of the web are to either write an ActiveX control or a Flash applet, both of which a tad more complicated than simple HTML. Aside from the complexity, both technologies are rapidly becoming obsolete.
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
To state a bit better, there is no need to search. The page is local in my laptop and so is C:\myFolder with files like a.html, b.html, c.html.

On my page, there is txtHtmlFileName in which I want to enter a.html, for example, and click on a button to open it in a new page.

If I cannot do this way, then I have to do it manually by going to the browser and scrolling up and down to locate a.html among some 40,000 other html files to open it manually.  

If desired code I am asking for is not possible, then I could use a code that sets the focus on the explorer with a.html, in this case, selected so that I could get it opened manual (saving me all the time otherwise I have to spend scrolling to find it).
käµfm³d 👽Commented:
Why scroll? Just type it in the "filename" box.

There is not Javascript way to interact with the file open dialog. The file open dialog is managed by the OS. The information returned from it is very limited. This is a security measure built into web browsers. Modern browsers won't even transmit the path when a user selects a file--only the filename is transmitted.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.