Calling OneNote GetHierarchy() from Silverlight Application
I have a Silverlight 4 out-of-browser, elevated trust application. I would like to use the OneNote 2010 object model to communicate with OneNote using the AutomationFactory and I'm not able to get the GetHierarchy() method of the Application to work. I know I have data in OneNote, because I can开发者_开发百科 call the method from a .NET application and get data back from it. The GetHierarchy() method returns null. Any suggestions?
class OneNoteAutomation
{
dynamic oneNote;
enum HierarchyScope
{
hsSelf = 0,
hsChildren = 1,
hsNotebooks = 2,
hsSections = 3,
hsPages = 4
}
public void GetHierarchy()
{
if (AutomationFactory.IsAvailable)
{
this.oneNote = AutomationFactory.CreateObject("OneNote.Application");
var result = this.oneNote.GetHierarchy(
string.Empty,
(int)HierarchyScope.hsNotebooks, 1);
}
}
}
This is a known bug that calls with methods that have 'out' cannot be used in AutomationFactory - please see SL4 - AutomationFactory - Call method with 'out' parameters raise exception: 'Could not convert an argument for the call to...'
BTW, I'm not sure what you are trying to do with the 1
in your GetHierarchy
call - that is the pointer to the string that will be filled with the XML of the chosen HierarchyScope
enum. It should be a string out
variable, instead of an integer - but regardless, it still won't work in SL4 due to the bug.
精彩评论