public static void SyncHyperLink(ref Hyperlink onenoteLink) { string currentHyperLink = onenoteLink.Address + onenoteLink.Arguments; try { string mmguid = currentHyperLink.Substring(currentHyperLink.IndexOf("mm-guid=")); //mmguid = mmguid.Replace("mm-guid", "").Replace("=", "").Replace("}", "").Replace("{", "").Replace('"', ' '); mmguid = mmguid.Replace('"', ' '); mmguid = mmguid.Replace(" ", "{", "}", "=", "mm-guid").Trim(); var newHyperlink = OnenoteUtils.GetHyperLinkBymmGuid(mmguid); if (newHyperlink != string.Empty) { //todo: does # inside strings adds a bookmark and what should be done. // otherwise it adds the #tail at the end of bookmarks onenoteLink.Bookmark = ""; newHyperlink += "&mm-guid={" + mmguid + "}"; var hl = Utils.GetMindManagerLink(newHyperlink); onenoteLink.Address = hl.Text; onenoteLink.Arguments = hl.Argument; } } catch (OneMapException ex) { throw new OneMapException("Error in SyncHyperLink", ex); } catch (Exception ex) { throw new OneMapException("Error in SyncHyperLink", ex); } finally { } }
private void btnDelete_Click(object sender, EventArgs e) { var document = _app.ActiveDocument; try { IEnumerator enumerator = document.Range(MmRange.mmRangeAllTopics, false).GetEnumerator(); while (enumerator.MoveNext()) { var topic = enumerator.Current as Topic; if (topic != null && topic.HasHyperlink) { foreach (var hyperlink in topic.Hyperlinks.AsEnumerable()) { if (Utils.IsValidLink(hyperlink)) { string currentHyperLink = hyperlink.Address + "#" + hyperlink.Bookmark + hyperlink.Arguments; string mmguid = currentHyperLink.Substring(currentHyperLink.IndexOf("mm-guid=")); mmguid = mmguid.Replace("mm-guid", "") .Replace("=", "") .Replace("}", "") .Replace("{", "") .Replace('"', ' '); var newHyperlink = OnenoteUtils.GetHyperLinkBymmGuid(mmguid); // MessageBox.Show("newhyperlink: " + newHyperlink); if (string.IsNullOrEmpty(newHyperlink)) { hyperlink.Bookmark = ""; hyperlink.Arguments = ""; hyperlink.Delete(); } } } } } Initialize(); } catch (COMException cex) { throw new OneMapException("btnDelete_Click-> couldn't delete link", cex.InnerException, cex.GetBaseException()); } catch (Exception ex) { throw new OneMapException("btnDelete_Click-> couldn't delete link"); } finally { Utils.ReleaseComObject(document); } }
private void Initialize() { lstLinks.Items.Clear(); var document = _app.ActiveDocument; var linkList = new List <Tuple <string, bool, string, string> >(); try { //todo: don't know what filter is used for IEnumerator enumerator = document.Range(MmRange.mmRangeAllTopics, false).GetEnumerator(); while (enumerator.MoveNext()) { var topic = enumerator.Current as Topic; if (topic != null && topic.HasHyperlink) { foreach (var hyperlink in topic.Hyperlinks.AsEnumerable()) { if (Utils.IsValidLink(hyperlink)) { string currentHyperLink = hyperlink.Address + "#" + hyperlink.Bookmark + hyperlink.Arguments; string mmguid = currentHyperLink.Substring(currentHyperLink.IndexOf("mm-guid=")); mmguid = mmguid.Replace("mm-guid", "") .Replace("=", "") .Replace("}", "") .Replace("{", "") .Replace('"', ' '); var newHyperlink = OnenoteUtils.GetHyperLinkBymmGuid(mmguid); // MessageBox.Show("newhyperlink: " + newHyperlink); //if newHyperlink is not empty then onenote page exists if (!string.IsNullOrEmpty(newHyperlink)) { var foundHyperLink = linkList.Any(x => x.Item4.Contains(newHyperlink)); if (!foundHyperLink) { if (currentHyperLink.Contains("§ion-id")) { linkList.Add( new Tuple <string, bool, string, string>( currentHyperLink.Substring(0, currentHyperLink.IndexOf("§ion-id")), true, topic.Guid, newHyperlink)); } else if (currentHyperLink.Contains("section-id")) { linkList.Add( new Tuple <string, bool, string, string>( currentHyperLink.Substring(0, currentHyperLink.IndexOf("section-id")), false, topic.Guid, newHyperlink)); } } } else { linkList.Add( new Tuple <string, bool, string, string>( currentHyperLink.Substring(0, currentHyperLink.IndexOf("§ion-id")), false, topic.Guid, newHyperlink)); } } } } Utils.ReleaseComObject(topic); } //LinkList.ForEach(x => lstLinks.Items.Add(x.Address)); linkList.ForEach(x => { if (!x.Item2) { int index = lstLinks.Items.Add(new MyListBoxItem(Color.Red, x.Item1)); } else { lstLinks.Items.Add(new MyListBoxItem(Color.Blue, x.Item1)); } }); } catch (Exception ex) { throw new OneMapException("ManageLinksfrm_Load()->Error Managing links", ex); } finally { Utils.ReleaseComObject(document); } }