Monday, February 23, 2009

Updating the OneNote Text File Importer

 

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

Published Monday, February 23, 2009 7:42 AM by JohnGuin

OneNote Testing : Updating the OneNote Text File Importer

No comments:

Blog Archive