private void webBrowserWiki_Navigating(object sender, WebBrowserNavigatingEventArgs e) { //For debugging, we need to remember that the following happens when you click on an internal link: //1. This method fires. url includes 'wiki:' //2. This causes LoadWikiPage method to fire. It loads the document text. //3. Which causes this method to fire again. url is "about:blank". //This doesn't seem to be a problem. We wrote it so that it won't go into an infinite loop, but it's something to be aware of. if (e.Url.ToString() == "about:blank" || e.Url.ToString().StartsWith("about:blank#")) { //This is a typical wiki page OR this is an internal bookmark. //We want to let the browser control handle the "navigation" so that it correctly loads the page OR simply auto scrolls to the div. } else if (e.Url.ToString().StartsWith("about:")) { //All other URLs that start with about: and do not have the required "blank#" are treated as malformed URLs. e.Cancel = true; return; } else if (e.Url.ToString().StartsWith("wiki:")) //user clicked on an internal link //It is invalid to have more than one space in a row in URLs. //When there is more than one space in a row, WebBrowserNavigatingEventArgs will convert the spaces into ' ' //In order for our internal wiki page links to work, we need to always replace the ' ' chars with spaces again. { string wikiPageTitle = Regex.Replace(e.Url.ToString(), @"\u00A0", " ").Substring(5); WikiPage wikiPageDeleted = WikiPages.GetByTitle(wikiPageTitle, isDeleted: true); //Should most likely be null. if (wikiPageDeleted != null) { if (MessageBox.Show(Lan.g(this, "WikiPage '") + wikiPageTitle + Lan.g(this, "' is currently archived. Would you like to restore it?"), "", MessageBoxButtons.OKCancel) != DialogResult.OK) { e.Cancel = true; return; } else { //User wants to restore the WikiPage. WikiPages.WikiPageRestore(wikiPageDeleted, Security.CurUser.UserNum); } } historyNavBack--; //We have to decrement historyNavBack to tell whether or not we need to branch our page history or add to page history LoadWikiPage(wikiPageTitle); e.Cancel = true; return; } else if (e.Url.ToString().Contains("wikifile:")) { string fileName = e.Url.ToString().Substring(e.Url.ToString().LastIndexOf("wikifile:") + 9).Replace("/", "\\"); if (!File.Exists(fileName)) { MessageBox.Show(Lan.g(this, "File does not exist: ") + fileName); e.Cancel = true; return; } try { System.Diagnostics.Process.Start(fileName); } catch (Exception ex) { ex.DoNothing(); } e.Cancel = true; return; } else if (e.Url.ToString().Contains("folder:")) { string folderName = e.Url.ToString().Substring(e.Url.ToString().LastIndexOf("folder:") + 7).Replace("/", "\\"); if (!Directory.Exists(folderName)) { MessageBox.Show(Lan.g(this, "Folder does not exist: ") + folderName); e.Cancel = true; return; } try { System.Diagnostics.Process.Start(folderName); } catch (Exception ex) { ex.DoNothing(); } e.Cancel = true; return; } else if (e.Url.ToString().Contains("wikifilecloud:")) { string fileName = e.Url.ToString().Substring(e.Url.ToString().LastIndexOf("wikifilecloud:") + 14); if (!FileAtoZ.Exists(fileName)) { MessageBox.Show(Lan.g(this, "File does not exist: ") + fileName); e.Cancel = true; return; } try { FileAtoZ.StartProcess(fileName); } catch (Exception ex) { ex.DoNothing(); } e.Cancel = true; return; } else if (e.Url.ToString().Contains("foldercloud:")) { string folderName = e.Url.ToString().Substring(e.Url.ToString().LastIndexOf("foldercloud:") + 12); if (!FileAtoZ.DirectoryExists(folderName)) { MessageBox.Show(Lan.g(this, "Folder does not exist: ") + folderName); e.Cancel = true; return; } try { FileAtoZ.OpenDirectory(folderName); } catch (Exception ex) { ex.DoNothing(); } e.Cancel = true; return; } else if (e.Url.ToString().StartsWith("http")) //navigating outside of wiki by clicking a link { try { System.Diagnostics.Process.Start(e.Url.ToString()); } catch (Exception ex) { ex.DoNothing(); } e.Cancel = true; //Stops the page from loading in FormWiki. return; } }