Saturday, September 09, 2006

 

OneNote 2007 Xml Viewer

Since OneNote extensibility revolves around an Xml-based interface its makes sense to deep dive into the Xml. In the earlier GetHierarchy posts I provided some basic demo code so you can view some of your OneNote's exported Xml in the console.

To make my life a little easier I created the OneNote Xml Viewer. It’s not rocket science, far from it in fact. The only OneNote object model method used by the OneNote Xml Viewer is GetHierarchy. Most of the code revolves around populating tree views, options, and parsing Xml. Simple as it is though it will give you a nice little User Interface to view the exported Xml.

Here's a screenshot:
onenote2007xmlviewer

Click here for a larger image....

I am not providing the base code on this little application. Not because I don’t wish to share, but because I used the bull in the china shop methodology for the User Interface code. As for the OneNote code I placed it all in a data access class and here it is:

//--------Start code -------

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.OneNote;

namespace unknown_onenote_blogspot
{
class ON_DataAccess
{
public ON_DataAccess()
{
_app = new ApplicationClass();
}

~ON_DataAccess()
{
_app = null;
}

public string GetAllInfo()
{
try
{
string resultsXml = "";
_app.GetHierarchy(null, HierarchyScope.hsPages , out resultsXml);
return resultsXml;
}
catch (Exception Ex)
{
throw Ex;
}
}

public string GetUnfiledNoteSection()
{
try
{
string unfiledNoteSectionID = "";
string loc = "";
_app.GetSpecialLocation(SpecialLocation.slUnfiledNotesSection, out loc);
_app.OpenHierarchy(loc, null, out unfiledNoteSectionID, CreateFileType.cftNone);
string resultsXml = "";
_app.GetHierarchy(unfiledNoteSectionID, HierarchyScope.hsPages, out resultsXml);
return resultsXml;
}
catch (Exception Ex)
{
throw Ex;
}
}

public string getNotebookXml(string notebookID, string hsScope)
{
string resultsXml = "";
try
{
_app.GetHierarchy(notebookID, getHsScope(hsScope), out resultsXml);
return resultsXml;
}
catch (Exception Ex)
{
return "Err";
}
}

public string getSectionXml(string sectionID, string hsScope)
{
string resultsXml = "";
try
{
_app.GetHierarchy(sectionID , getHsScope(hsScope) , out resultsXml);
return resultsXml;
}
catch (Exception Ex)
{
return "Err";
}
}

public string getSectionGroupXml(string sectionID, string hsScope)
{
string resultsXml = "";
try
{
_app.GetHierarchy(sectionID, getHsScope(hsScope), out resultsXml);
return resultsXml;
}
catch (Exception Ex)
{
return "Err";
}
}

public string getPageXml(string sectionID, string hsScope)
{
string resultsXml = "";
try
{
_app.GetHierarchy(sectionID, getHsScope(hsScope) , out resultsXml);
return resultsXml;
}
catch (Exception Ex)
{
return "Err";
}
}

private HierarchyScope getHsScope(string scope)
{
switch (scope.ToUpper())
{
case "HSSELF": return HierarchyScope.hsSelf;
case "HSSECTIONS": return HierarchyScope.hsSections;
case "HSNOTEBOOKS": return HierarchyScope.hsNotebooks;
case "HSPAGES": return HierarchyScope.hsPages ;
case "HSCHILDREN": return HierarchyScope.hsChildren;
default: return HierarchyScope.hsSelf;
}
}
ApplicationClass _app;
}
}

// ------ End Code ---------
If you were really planning on using this data access class I would seriously look at a little refactoring. I tossed it together late one night.

A few things to note about this application - I would not consider this a solid app. There was little if any design, no refactoring, and the User Interface portion was beat into submission with a stick - sorry I am a Web Developer and more behind the scenes then out in front. Big disclaimer here - please don’t use this in your mission critical applications. You get what you pay for in this application. It is meant for entertainment purposes only!

Also if you read Daniel Escapa's blog you will know that when Tech Refresh releases the namespace will more than likely change. But don’t worry - the namespace for this application is stored in the app configuration. So assuming GetHierarchy and the OneNote xml schema has not changed (other than the namespace) you can easily replace the old namespace with the new namespace by editing the config file.

The file is avaialble for download at this location:

http://oreys.com/download/2670f5718826/OneNote2007XmlViewer.zip.html

This is a free file hosting page and it seemed pretty innocuous. It seems like Blogger does not support any file hosting outside of basic images. Let me know if you have trouble bringing this zip file down. It contains two files, the exe and the config. Place them both in the same directory on a machine with OneNote 2007 Beta 2 installed and have a look around your Notebooks.

Check out the menu for options to select all, export the Xml to the file system and change the scope options. I intentially left all scopes in so you can play with Node Type v Hierarchial Scope. See my previous post. Some combos will return an error - you can check the post on Node Type v Hierarchial Scope to see what combos will give you errors.


Comments:
The schema namespace will be the same in in B2TR; the final name is only in post-B2TR (so RTM for everyone). There are changes to the schema, but otherwise your app should work just fine with B2TR.
-descapa
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?



website statistics