I can see at least one problem: indirect recursion (
http://en.wikipedia.org/wiki/Recursion[
^]).
When you call
Navigate
, your browser gets to loading the another document, which leads to invocation of your
Load
event again. Recursion is "infinite". You need to isolate the case of navigation to "docs.google.com/viewer?url=" from the navigation to a Word document. Also, you need to cancel navigation to a Word document.
Do something like
if (myBrowser.Url.ToString.ToLower().StartsWith("http://docs.google.com/viewer?url=")) exit;
or something like that.
Also, fix your Regex as I explained in my comment to the question, please see. Or, simpler, use
strong.ToLower
and
string.EndsWith
, like:
string loUrl = myBrowser.Url.ToString.ToLower();
if (liUrl.endsWith(".docx") || liUrl.endsWith(".doc"))
Please see:
http://msdn.microsoft.com/en-us/library/system.string.aspx[
^].
This is not a final solution, but I think very close. Just work a bit in this direction.
By the way, I don't see a need in WebKit. If you work on Windows only, you can do the same thing with one of the
WebBrowse
classes already available in .NET FCL.
—SA