c# - MSDN OneNote Api: Navigate to never before opened page without opening a OneNote Application Window -
my goal able use c# programmatically open .one section file , of section's page ids. in simple case (one have created , used section), can done following code:
using microsoft.office.interop.onenote; class program { public static void processonenotefile() { application onenoteapp = new application(); string filepath = @"c:\users\admin\documents\onenote notebooks\my notebook\testsection.one"; string sectionid; onenoteapp.openhierarchy(filepath, null, out sectionid); string hierarchy; onenoteapp.gethierarchy(sectionid, hierarchyscope.hspages, out hierarchy); file.writealltext(@"c:\hierarchy.txt", hierarchy); } }
from here can parse xml find pageids , go.
the problem, however, want files getting else , have never opened before. when run same code on files, cannot find pageids in hierarchy, , therefore, cannot process pages. fix seems work use navigateto method open section file in onenote before trying hierarchy.
... string sectionid; onenoteapp.openhierarchy(filepath, null, out sectionid); onenoteapp.navigateto(sectionid); string hierarchy ...
this, however, quite annoying need open onenote application. since have many .one section files process lot of random information flashing across screen not necessary , might confuse end users of program. there way can achieve same result of adding pageids hierarchy without needing open onenote application? @ least, there way can hide application?
update:
i noticed using publish command updates hierarchy pageids, however, solution still not ideal requires me make anotehr file.
also, looking more closely @ xml export, saw there attribute called "areallpagesavailable" set false me on files have yet open in onenote.
woohoo! after couple hours of playing around , google searching different methods, have found after.
solution: synchierarchy(sectionid);
... string sectionid; onenoteapp.openhierarchy(onenotefile, null, out sectionid, createfiletype.cftsection); onenoteapp.synchierarchy(sectionid); string hierarchy; onenoteapp.gethierarchy(sectionid, hierarchyscope.hspages, out hierarchy); ...
Comments
Post a Comment