Updating the OneNote Text File Importer


I received an email which pointed out a limitation and a design problem with the OneNote Text File Importer. First – the design issue.

If you click the Browse button:

clip_image001

You can choose a single folder from which to import:

clip_image002

Remember, when you import the text files in the folder, a new section with the folder name will be created and each text file will get imported as a new page. But that’s it – subfolders to the original folder are not supported. Willem sent me a simple one line fix for that:

//Willem added SearchOption.AllDirectories.

               string[] fileName = Directory.GetFiles(pathToTextFiles, "*.txt", SearchOption.AllDirectories);

The original line was

               string[] fileName = Directory.GetFiles(pathToTextFiles, "*.txt");

With this change, any text files found in any subfolder will also get imported. On one hand, this is pretty slick and saves a lot of clicking around and reselecting if you have a large hierarchy of folders with text files in them. On the other hand, all the text files get put into one section. I had originally designed the tool this way. If you wanted to import any folder, you were really encouraged to import one folder at a time and decide when you imported where you wanted the new section. I like Willem’s change, too, though.

I was thinking about this over the weekend and received a comment from Willem that it should not be mandatory. Willem wanted it controlled by a checkbox – fair enough. Then I thought that the subfolders on the hard drive need to get imported as "sub sections" in OneNote, but couldn’t figure out a good way to create a section group and the section each would require. Duplicate names between the sections and section groups? The tester in me points out it would require a file name length check since the paths to all those subfolders can get pretty long. Thoughts, anyone?

The new files as of 2/23/2009 do NOT have this subfolder change.

The next problem was clearly a bug. Multiline text files lost the end of line characters (the carriage returns, if you will). All the text ran together after import.

The problem was converting from text format to HTML (which is what OneNote expects). In text files, end of lines are typically stored as

"\r\n" (return and newline characters).

In HTML, line breaks are stored as

"<BR>"

So the change to fix this problem was create a little routine to change the "\r\n" to "<BR>". Ultimately, this boiled down to another one line fix:

string st2 = pText.Replace("\r\n", "<BR>");

Hopefully, this change will make this powertoy a bit better to use. The new files are posted and the links are at the original page.

Thanks for the bug reports!

Questions, comments, concerns and criticisms always welcome,

John


Comments (14)

  1. armon says:

    Hi

    Is there any possibility that importer would support .html extensions?

    I have bunch of bookmark files(FF) and I would like to import them into Onenote.

    thanks

  2. JohnGuin says:

    Hi Armon,

    While I hate saying "no," I can’t promise to get HTML support added.  It is a pretty big work item to do so.  Maybe someone else here can grab the code and give it a whirl?

    John

  3. kartal says:

    Reverse text tool?

    Hi

    Is it possible to export contents as txt files? That would be so great!! I understand that there might be some things lost along the way but this is better than nothing.

  4. John says:

    You can copy the entire XML with OMSpy.  That would include the text, who modified it, when, what fonts are used, etc…  That would probably be much more useful than text.

    John

  5. armon says:

    Hi

    I keep coming back to this topic 🙂 I have another idea regarding this text import tool. I think that it would be overly beneficial(at least to me) to have a live version of this importer. By live I mean a tool that watches certain folder(s) for changes and additions of files. If anything has changed the tool would updates-reimports and imports the changes into ON without asking for further approval, so basically it does the job in the background. The reason I am asking for such thing is that I myself use multiple applications to keep my notes and I really would like to be able to share notes among them as much as possible.

    thanks

  6. armon says:

    Hi

    I keep coming back to this topic 🙂 I have another idea regarding this text import tool. I think that it would be overly beneficial(at least to me) to have a live version of this importer. By live I mean a tool that watches certain folder(s) for changes and additions of files. If anything has changed the tool would updates-reimports and imports the changes into ON without asking for further approval, so basically it does the job in the background. The reason I am asking for such thing is that I myself use multiple applications to keep my notes and I really would like to be able to share notes among them as much as possible.

    thanks

  7. armon says:

    How can I export the whole content as xml out of Omspy? I do not see any exporting option in Omspy?

  8. John says:

    I usually just use the mouse to select what I want and CTRL+C to copy.  If I need it all, CTRL+A does NOT work, so I click at the top and SHIFT+PG DN to select the XML.

  9. Jim says:

    John: When I use the text importer it only works for 6 text files, no matter how many others are in the folder. I'm using version 2007 with an Asus EEE and Windows XP. I have 1 GB of RAM. Any ideas?

  10. JohnGuin says:

    I would suspect a text file is in a non-supported format (Endian, possibly unicode).  Can you narrow down if it is a specific file?  Nothing in the code has a limit of 6.

    To test, you could copy the 6 files that work to a new folder twice to create a folder with 12 "good" files.  Can you import all the 12 files in that folder?

  11. Dirk says:

    John,

    I've been able to successfully use the VB Script to convert all my Outlook notes to text files, neatly categorized in their respective folders. Unfortunately I am unable to get the Text File Importer to work. After install and I click on the .exe, it just says " Application has stopped working, checking for a fix." I even rebuilt the code into a new exe on my machine, but still to no avail. I'm running Windows 7 64 bit. Is there a way around my problem? I'm really excited about using OneNote on my main PC and my Apple devices as my main note and task management tool. But I'd hate to have to convert 500+ notes manually. Any help would be appreciated. Thanks.

  12. JohnGuin says:

    If you rebuilt and are still seeing errors, I would check the .NET framework next.  And what exactly do you mean for "Install?" You should just be able to run the exe.

    Lastly, can you step through the code in the debugger?

  13. Dirk says:

    Hi John,

    Well, the zip file contains setup.exe and an MSI file, so an install is required. I then get three files: Johnicon.ico,  MS.Interop.OneNote.dll and Text File Importer.exe. The exe doesn't work, just hangs.

    Thanks,

    Dirk