I can see at least one problem: indirect recursion (http://en.wikipedia.org/wiki/Recursion
When you call
, your browser gets to loading the another document, which leads to invocation of your
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
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
classes already available in .NET FCL.