Skip to content
grillod edited this page Mar 26, 2023 · 15 revisions
  • This is my own personal app I use to create a generic backup of things I keep in my Evernote account.
  • I use it happily all the time. It gives me piece of mind. It doesn’t crash or have any unexpected behavior for me. But my use cases are always wildly divergent from what a normal person may do. So it may not actually be useful to anyone else.
  • This code might be a good starting point to doing something more useful with ENEX exports. Feel free to use any of the code here for any reason.

Things that I don’t care about and should cause you to move along if you do care about them.

  • It not being useful to you.
  • To cumbersome to use.
  • Someone else may have done it better
  • You may feel that the native export functionality is just fine and you have no idea why anyone would want to do things this way
  • The code may seem idiotic, unstructured and not use the one true bracket style you adhere to.

Use

  • I use the evernote legacy client to create .ENEX backups of everything in my account.

  • Legacy allows you to export large numbers of notes where as the new electron client does not.

    https://help.evernote.com/hc/en-us/articles/209005557-Export-notes-and-notebooks-as-ENEX-or-HTML

    https://evernote.com/blog/how-evernotes-xml-export-format-works/

  • ENEX is an XML format that keeps a lot of things in base 64, which is fine but not usable as a real useful backup. I wanted a folder structure I could browse around in.

    Even the HTML export options in the Evernote client don’t create a real good way to do this. They seem to put everything in one large html file. I can’t really remember why it wasn’t sufficient for me but it wasn’t.

    And most importantly, they don’t maintain any kind of folder structure.

  • This rough code I use does this but requires tagging to accomplish it.

    In every folder, every note must be tagged with the same notebook tag that is prefaced with “ZZ_” . Yeah this is a lot of initial overhead. I haven’t found a better way to do it. And now that I have, it’s easy to maintain as I create new notes.

    For example, every note in the Quotes2 notebook needs the tag “ZZ_Quotes2”. This will be the cue the code needs to create a folder for the Quotes2 folder. All Notes with this tag will be stored under the Quotes2 Folder.

image

After everything is tagged appropriately, go into Evernote legacy, select a large amount of notes and export them to ENEX.

Copy that file to the Enex file path specified in the code. “d:\tmp”

Start the app and press the only button there is.

You may want to do this in chunks of 1000 notes. More or less depending on how fast the code runs.

Folder structure will be created under the default d:\MailBackups\EverNoteBackup folder. Every note tagged with ZZ_ will be stored in a folder named appropriately.

image

  • Every folder will have other folders ~named for each note in the notebook.

image

  • Each note folder will contain html of the body of the note. And other files for every file attached to the note.

image

  • The .html file with the note name will contain the body of the note. It will look something like below. The body of the note followed by an attachments section listing each attachment.

image

The Code:

  • It’s c# .net

  • In Form1.cs you can and should alter the constants to your liking

    EnexFilePath is the constant to define the path of where the code should look to find ENEX files to parse. Note files parsed in this folder will be deleted after parsing. Feel free to comment that part out.

    NoteBookIdentifierPrefix is the constant used by the code to determine which tags are the ones meant to identify a notebook – which it will use to create folders on the file system. I chose “ZZ_” because it’s something that won’t likely be used for anything else and will be at the bottom of the tag list when in the UI.

    RootOutputFolder is the constant where the backups will be made.

  • It only handles basic Evenote notes. I know there are notes that are like “Tasks”, But I don’t use them and I haven’t seen what happens if the code is run against one.

  • The enex parsing code was pieced together from the ENEX file standard description and trial and error.

    Sometimes things occurred when parsing that weren’t described in the standard and caused crashes. When this happened I did my best to handle what I thought was happening gracefully without losing data. At the time of this document, I haven’t received any parsing crashes for months.