Source code for the Bulk Ink Eraser powertoy

The source code for this powertoy is attached below my signature at the end of this column. It's really just the inkeraserclass.cs  file- everything else is just the setup/interface for it.

The code here was fairly straightforward but still took some time for me to understand how to get all the ink on the page. According to the schema, ink on a page is stored in three different nodes: InkDrawing, InkWords or InkParagraphs. Since OneNote exposes all the content as XML, the code just finds those three nodes and deletes them from the page.

Next, ink can be stored at two different levels- on the page as a Page Level object, or within an outline. To a user, the ink in an outline will show in a container and the page level will not. First, I delete the ink at the page level. Since this is page level content, I can use the DeletePageContent method OneNote exposes to delete the ink:

onApp.DeletePageContent(strActivePageID, inkWordNodes[i].Attributes["objectID"].Value);

The same routine appies for InkParagraphs and InkDrawings.

I like to think of the "DeletePageContent" method as "delete page level content." It can delete any object that exists at the page level.

Originally, I had hoped to simply use it to delete any outline that contains ink. A very little bit of testing told me this would not work. An outline can contain more content than just ink within its outline elements - it can also hold text, for instance. So if I delete the entire outline that contain ink, I could delete text from the page as well, which is clearly not the behavior I wanted. So what I do is look at all the Ink* nodes on the page, loop up to get their parent node (an outline element) and delete only the outline elements that contain ink.

XmlNodeList inkDrawingNodes = xmlDoc.SelectNodes("//one:InkDrawing", nsmgr);

for (int i = 0; i < inkDrawingNodes.Count; i++){

XmlNode oeNode = inkDrawingNodes[i].ParentNode;

The code simply removes the node from the page XML. Once the three ink types are removed, I just call UpdatePageContent with the corrected XML:

    onApp.UpdatePageContent(xmlDoc.InnerXml, System.DateTime.MinValue);

I do this separately from the method which deletes the page level ink. That simply makes the code easier to read.

Throw in some error checking and debugging code and that's all there is to it. If you want to build this, you will probably want to create an icon named "red_onenote_icon.ico." That icon was more than tripling the size of the zip file, so I just took it out to make the file smaller.

If needed, you can press CTRL+Z to undo the deletion if needed.


Questions, comments, concerns and criticisms always welcome,


Comments (1)

  1. M.Ahrens says:

    A very insightful post. Thanks for the info.

Skip to main content