Using Local File Links in Web Browser Control

  • Thread starter Christopher D. Wiederspan
  • Start date
C

Christopher D. Wiederspan

I've got a WebBrowser control in a C# Windows form. I build HTML on the fly
and then set it into the control using the DocumentText property of the
control. All of this works fine, except that part of the HTML that I
construct is an <A> element that links to a local file, something like this:

<A HREF="C:\Temp\SomeFile.htm" TARGET="_blank">Test</A>

When I click on the link in the browser control, nothing happens.

After some experimentation, I've learned that if I share my Temp directory
and then use this HTML instead, it works:

<A HREF="\\MyMachine\Temp\SomeFile.htm" TARGET="_blank">Test</A>

Can anybody give me some insight into this - I'm stuck without having the
ability to link up to local files.

Thanks,
Chris
 
A

AHN

First, you shouldn't crosspost.

Next, in your <A>, try 'href="file://C:\Temp\SomeFile.htm"'. The other link
works probably because it is being treated like a web-link with your
machine's server as the root. Again it's not correct. It shouldn't work. I
don't like it, but never mind. :)


I've got a WebBrowser control in a C# Windows form. I build HTML on the fly
and then set it into the control using the DocumentText property of the
control. All of this works fine, except that part of the HTML that I
construct is an <A> element that links to a local file, something like this:

<A HREF="C:\Temp\SomeFile.htm" TARGET="_blank">Test</A>

When I click on the link in the browser control, nothing happens.

After some experimentation, I've learned that if I share my Temp directory
and then use this HTML instead, it works:

<A HREF="\\MyMachine\Temp\SomeFile.htm" TARGET="_blank">Test</A>

Can anybody give me some insight into this - I'm stuck without having the
ability to link up to local files.

Thanks,
Chris
 
C

Christopher D. Wiederspan

Yes, I tried everything I could thing of to come up with different paths and
even prepending the "file://" onto the front didn't help.

Any other ideas?

Chris
 
A

AHN

Doubleclick on your inserted htm file to open it with IE (or whatever your
default browser is). Click on Test. Does a new instance of the browser
appear with SomeFile.htm or not? If yes, pay attention how you load the file
into the webcontrol. If no, check your html.

Yes, I tried everything I could thing of to come up with different paths and
even prepending the "file://" onto the front didn't help.

Any other ideas?

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top