private string GetSection(string sectionName) { string newnbID = ""; try { // remove and/or replace characters that are not allowed in Onenote section names sectionName = sectionName.Replace("?", ""); sectionName = sectionName.Replace("*", ""); sectionName = sectionName.Replace("/", ""); sectionName = sectionName.Replace("\\", ""); sectionName = sectionName.Replace(":", ""); sectionName = sectionName.Replace("<", ""); sectionName = sectionName.Replace(">", ""); sectionName = sectionName.Replace("|", ""); sectionName = sectionName.Replace("&", ""); sectionName = sectionName.Replace("#", ""); sectionName = sectionName.Replace("\"", "'"); sectionName = sectionName.Replace("%", ""); string xmlHierarchy; onApp.GetHierarchy("", OneNote.HierarchyScope.hsNotebooks, out xmlHierarchy); onApp.OpenHierarchy(m_EvernoteNotebookPath + "\\" + sectionName + ".one", "", out newnbID, OneNote.CreateFileType.cftSection); string xmlSections; onApp.GetHierarchy(newnbID, OneNote.HierarchyScope.hsSections, out xmlSections); // Load and process the hierarchy XmlDocument docHierarchy = new XmlDocument(); docHierarchy.LoadXml(xmlHierarchy); StringBuilder Hierarchy = new StringBuilder(sectionName); AppendHierarchy(docHierarchy.DocumentElement, Hierarchy, 0); } catch (Exception /*ex*/) { //MessageBox.Show(string.Format("Exception creating section \"{0}\":\n{1}", sectionName, ex.ToString())); } return(newnbID); }
private void Startsync_Click(object sender, EventArgs e) { ENNotebookName = this.notebookCombo.SelectedItem as string; if (m_enexfile != null && m_enexfile.Length > 0) { ENNotebookName = Path.GetFileNameWithoutExtension(m_enexfile); } if (ENNotebookName.Length == 0) { MessageBox.Show("Please enter a notebook in EverNote to import the notes from", "Evernote2Onenote"); return; } if (m_enexfile != null && m_enexfile.Length > 0) { enscriptpath = ProgramFilesx86() + "\\Evernote\\Evernote\\ENScript.exe"; if (!File.Exists(enscriptpath)) { MessageBox.Show("Could not find the ENScript.exe file from Evernote!\nPlease select this file in the next dialog.", "Evernote2Onenote"); OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Applications|*.exe"; openFileDialog1.Title = "Select the ENScript.exe file"; openFileDialog1.CheckPathExists = true; // Show the Dialog. if (openFileDialog1.ShowDialog() == DialogResult.OK) { enscriptpath = openFileDialog1.FileName; } if (!File.Exists(enscriptpath)) return; } } onApp = new OneNote.Application(); if (onApp == null) { MessageBox.Show("Could not start Onenote!", "Evernote2Onenote"); return; } // create a new notebook named "EverNote" try { string xmlHierarchy; onApp.GetHierarchy("", OneNote.HierarchyScope.hsNotebooks, out xmlHierarchy); // Get the hierarchy for the default notebook folder onApp.GetSpecialLocation(OneNote.SpecialLocation.slDefaultNotebookFolder, out m_EvernoteNotebookPath); m_EvernoteNotebookPath += "\\" + ENNotebookName; string newnbID; onApp.OpenHierarchy(m_EvernoteNotebookPath, "", out newnbID, OneNote.CreateFileType.cftNotebook); string xmlUnfiledNotes; onApp.GetHierarchy(newnbID, OneNote.HierarchyScope.hsPages, out xmlUnfiledNotes); // Load and process the hierarchy XmlDocument docHierarchy = new XmlDocument(); docHierarchy.LoadXml(xmlHierarchy); StringBuilder Hierarchy = new StringBuilder(); AppendHierarchy(docHierarchy.DocumentElement, Hierarchy, 0); } catch (Exception) { try { string xmlHierarchy; onApp.GetHierarchy("", OneNote.HierarchyScope.hsPages, out xmlHierarchy); // Get the hierarchy for the default notebook folder onApp.GetSpecialLocation(OneNote.SpecialLocation.slUnfiledNotesSection, out m_EvernoteNotebookPath); onApp.OpenHierarchy(m_EvernoteNotebookPath, "", out newnbID, OneNote.CreateFileType.cftNone); string xmlUnfiledNotes; onApp.GetHierarchy(newnbID, OneNote.HierarchyScope.hsPages, out xmlUnfiledNotes); m_bUseUnfiledSection = true; } catch (Exception ex2) { MessageBox.Show(string.Format("Could not create the target notebook in Onenote!\n{0}", ex2.ToString())); return; } } if (startsync.Text == "Start Import") { startsync.Text = "Cancel"; MethodInvoker syncDelegate = new MethodInvoker(ImportNotesToOnenote); syncDelegate.BeginInvoke(null, null); } else { cancelled = true; } }
private void Startsync_Click(object sender, EventArgs e) { ENNotebookName = this.notebookCombo.SelectedItem as string; if (m_enexfile != null && m_enexfile.Length > 0) { ENNotebookName = Path.GetFileNameWithoutExtension(m_enexfile); } if (cmdNoteBook.Length > 0) { ENNotebookName = cmdNoteBook; } if (ENNotebookName.Length == 0) { MessageBox.Show("Please enter a notebook in EverNote to import the notes from", "Evernote2Onenote"); return; } if (m_enexfile != null && m_enexfile.Length > 0) { enscriptpath = ProgramFilesx86() + "\\Evernote\\Evernote\\ENScript.exe"; if (!File.Exists(enscriptpath)) { MessageBox.Show("Could not find the ENScript.exe file from Evernote!\nPlease select this file in the next dialog.", "Evernote2Onenote"); OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Applications|*.exe"; openFileDialog1.Title = "Select the ENScript.exe file"; openFileDialog1.CheckPathExists = true; // Show the Dialog. if (openFileDialog1.ShowDialog() == DialogResult.OK) { enscriptpath = openFileDialog1.FileName; } if (!File.Exists(enscriptpath)) { return; } } } try { onApp = new OneNote.Application(); } catch (Exception ex) { MessageBox.Show(string.Format("Could not connect to Onenote!\nReasons for this might be:\n* The desktop version of onenote is not installed\n* Onenote is not installed properly\n* Onenote is already running but with a different user account\n\n{0}", ex.ToString())); return; } if (onApp == null) { MessageBox.Show(string.Format("Could not connect to Onenote!\nReasons for this might be:\n* The desktop version of onenote is not installed\n* Onenote is not installed properly\n* Onenote is already running but with a different user account\n\n{0}")); return; } // create a new notebook named "EverNote" try { string xmlHierarchy; onApp.GetHierarchy("", OneNote.HierarchyScope.hsNotebooks, out xmlHierarchy); // Get the hierarchy for the default notebook folder onApp.GetSpecialLocation(OneNote.SpecialLocation.slDefaultNotebookFolder, out m_EvernoteNotebookPath); m_EvernoteNotebookPath += "\\" + ENNotebookName; string newnbID; onApp.OpenHierarchy(m_EvernoteNotebookPath, "", out newnbID, OneNote.CreateFileType.cftNotebook); string xmlUnfiledNotes; onApp.GetHierarchy(newnbID, OneNote.HierarchyScope.hsPages, out xmlUnfiledNotes); // Load and process the hierarchy XmlDocument docHierarchy = new XmlDocument(); docHierarchy.LoadXml(xmlHierarchy); StringBuilder Hierarchy = new StringBuilder(); AppendHierarchy(docHierarchy.DocumentElement, Hierarchy, 0); } catch (Exception) { try { string xmlHierarchy; onApp.GetHierarchy("", OneNote.HierarchyScope.hsPages, out xmlHierarchy); // Get the hierarchy for the default notebook folder onApp.GetSpecialLocation(OneNote.SpecialLocation.slUnfiledNotesSection, out m_EvernoteNotebookPath); onApp.OpenHierarchy(m_EvernoteNotebookPath, "", out newnbID, OneNote.CreateFileType.cftNone); string xmlUnfiledNotes; onApp.GetHierarchy(newnbID, OneNote.HierarchyScope.hsPages, out xmlUnfiledNotes); m_bUseUnfiledSection = true; } catch (Exception ex2) { MessageBox.Show(string.Format("Could not create the target notebook in Onenote!\n{0}", ex2.ToString())); return; } } if (importDatePicker.Value > cmdDate) { cmdDate = importDatePicker.Value; } if (startsync.Text == "Start Import") { startsync.Text = "Cancel"; MethodInvoker syncDelegate = new MethodInvoker(ImportNotesToOnenote); syncDelegate.BeginInvoke(null, null); } else { cancelled = true; } }