Working on a verification for printing to OneNote

Spent some time last week working on a script to verify that the printer actually works when printing from an application to OneNote. I learned a little something about our OneNoteOfflineCache_Files that I thought may be interesting as well. I'll start with that.

The OneNoteOfflineCache_Files folder is a stored in the subfolder of the OneNote cache. You can see where that is by looking in Tools | Options and examining the Save tab. If you have OneNote 2010, you can see this in File | Options and looking at the Save & Backup tab. This is what it looks like on my XP machine:

clip_image001

The folder that I need to work with is named "OneNoteOfflineCache_Files" and would be a subfolder under this path. So the full path in this case would be C:\Documents and Settings\johngui\Local Settings\Application Data\Microsoft\OneNote\14.0\OneNoteOfflineCache_Files.

If you jump to that folder now you will probably see a ton of files named {GUID}. I'll come back to that.

What I want this particular code to do is verify the proper set of files get added to that folder when I insert a printout. When I insert any document into OneNote (as an embedded file), a copy of it gets created here with a {GUID} for a name. OneNote uses this as a cached copy of the actual file - in case you want to view it when you are disconnected from the network, for instance. Embedded images also get save here. We give the file a GUID to help prevent "name collisions." Imagine the trouble if you had 20 files named "readme.txt" added from all over - we'd need some method to find out which one you meant to open if you clicked the icon in OneNote. We just renamed the cached copy to a {GUID} to help prevent this type of problem.

Moving on to printing, if I print a text document that is 2 pages long to OneNote, I should get 2 images added to that folder- one for each page. I also get a third image added to show as the icon for the icon type of the embedded file. It should be a text file in my case (I'm going to print a plain text document here to start). I should also get a copy of the text file since it will get added as an embedded file as well. And I should get an XPS file since the OneNote printer prints to the XPS printer and just uses its output. So printing this document should add 5 total files to that folder - 3 image files (PNG), 1 text file and 1 XPS file.

Our automation system automatically ensures a clean machine when we run, and the setup part of this script creates a barebones notebook with a single blank page ready for testing. I did not change any of that and wrote the script to print the text file to OneNote and ensured that the number of PNG files when done was 3, text files was 1 and XPS files was 1. And the script failed.

Here's where I learned something new (you learn something new every day around here). I looked in the folder and noticed 70 some odd files were there. Thinking there was a bug in the setup for the test code, I deleted them all and restarted. And they came back. I opened a few of the PNG files and they looked like the backgrounds from some of the default templates. It turns out that is exactly what they are - the images from the templates. They get cached here so they can be more quickly accessed when OneNote is running.

Since I don't care about templates for this particular test, I wrote a routine to clean the folder right before my test runs. Now this file check verification works just fine.

I strongly DO NOT recommend deleting this files.  All your embedded items in a notebook will be broken.  This is a good example, though, of where automation need not simulate a regular user to perform a verification.

More on that later.

Questions, comments, concerns and criticisms always welcome,

John