none
OneNote - UpdatePageContent - The section is read-only (0x8004200b) RRS feed

  • Question

  • I have a OneNote notebook "template" that I copy into a new folder when I start a new project.  I'm trying to write an application to update a couple hyperlinks on one of the pages in a section in the notebook.

    using Microsoft.Office.Interop.OneNote;
    // ...
    Microsoft.Office.Interop.OneNote.Application oneApp = new Microsoft.Office.Interop.OneNote.Application();
    oneApp.OpenHierarchy(filePath, string.Empty, out strID);
    oneApp.GetPageContent(strID, out pageXMLContent);
    // code to determind the ID of the page I want to update & update strID
    oneApp.GetPageContent(strID, out pageXMLContent);
    // code to replace hyperlink content here
    oneApp.UpdatePageContent(pageXMLContent);

    I get a COMException - Exception from HRESULT: 0x8004200B on the UpdatePageContent line, which the error codes section of the developer reference says is 'The section is read-only'.  How do I change the section to not be read-only?

    In the first GetPageContent results there is a 'readOnly=true' property...I have tried updating the pageXMLContent to say 'readOnly=false' and set it with an UpdateHierarchy command, but it doesn't seem to change anything (GetPageContent returns the exact same thing afterwards).  I've also try ensuring that read-only and archive options are not checked on the file properties of the OneNote notebook files and moving the notebook from a network location to the My Documents folder on my local drive to try to make sure it isn't a file access issue.

    I've done a fair amount of Google searching and have skimmed through most of the OneNote Developer Reference material and haven't seen anything about this issue...any help would be appreciated.

    Wednesday, February 5, 2014 2:28 PM

All replies

  • Hi,

    >> I get a COMException - Exception from HRESULT: 0x8004200B on the UpdatePageContent line, which the error codes section of the developer reference says is 'The section is read-only'. 

    #Error Codes (OneNote 2010)
    http://msdn.microsoft.com/en-us/library/ff966472.aspx

    # helping out on the discussion group for making notes “permanent”
    http://blogs.msdn.com/b/johnguin/archive/2010/03/25/helping-out-on-the-discussion-group-for-making-notes-permanent.aspx

    It looks like you're trying to update the read-only page, and I noticed you mentioned you have checked the read-only attributes and archive options are not checked, Can you open this *.one file and modify it in OneNote application ? When you open it in OneNote, Can you see (Read -only) along the top of the frame?
    And then mark sure none of application may use this file when you call UpdatePageContent method.

    Here is some reference about how to get and update the page content in OneNote.

    # Creating OneNote 2010 Extensions with the OneNote Object Model
    http://msdn.microsoft.com/en-us/magazine/ff796230.aspx

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Edited by Marvin_Guo Friday, February 7, 2014 5:50 AM
    Friday, February 7, 2014 5:46 AM
  • Thank your for your response, and thanks for posting the link to the error codes in the developer reference...I had not confirmed my account yet so I wasn't able to include the link in my post.

    One the file properties:  I am clearing the read-only box in file properties.  The folder still indicates that it is read only, but the .one file is not (square in read-only box for folder, completely clear on file).  Clearing the box on the folder appears to work, but if I close the properties window and re-open, it is back...I haven't looked into this too much because of my next point.

    Editting the page through the OneNote application works fine.  Nothing is read-only, changes are applied without any fuss.  When I initially started this, the OpenHierarchy call would hang if OneNote was open, so my first step every time is to check for the ONENOTE process and close it if it is running.  I was also initially trying this against a notebook that I had stored in a private network location with very limited access and no one else would have had this particular notebook open, but I've since moved it to my C drive to try as I was thinking I might be running into issues because of the network.

    I did just notice that I was using the 12.0.0.0 version of Microsoft.Office.Interop.OneNote.dll, so maybe that is the source of some of my trouble? I've downloaded the 14.0.0.0 version & am going to update my application to reference it instead.  I'll post again when I see if that does anything for me.

    EDIT:

    I finally had some time to play with this some more, but I've quickly gotten stuck again.  After replacing the version 12 dll w/ the version 14, I get a 'MisingMethodException'.  I'm still looking around for more information about this online, however I figured I might as well post it in case someone can point me in the right direction.  Exception details:

    System.MissingMethodException was unhandled
      Message=Method not found: 'Void Microsoft.Office.Interop.OneNote.Application..ctor()'.
    
    • Edited by aatrumble Sunday, February 9, 2014 7:57 PM
    Friday, February 7, 2014 3:00 PM
  • Hi,

    >>After replacing the version 12 dll w/ the version 14, I get a 'MisingMethodException'. 

    I want to know the version of your OneNote and which line of code throw this exception?

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 12, 2014 5:04 AM
  • I'm using Office 2010...OneNote version in File > Help is 14.0.6129.5000.  The version of the Microsoft.Office.Interop.OneNote reference reported in VS is 14.0.0.0, however browsing to the file on the hard drive & looking at the details tab of the file properties for it shows 14.0.4733.1000.

    I started my application as kind of a 'sandbox' & have the interactions with the OneNote dll in a separate class than the UI.  I have a button click event that calls a public method from that class and the exception is thrown as soon as I try to step into the method (breakpoint is on the method call from the UI class & the debugger never jumps over to the file containing my other class...)

    From some of the research I've done it sounds like maybe my application is referencing the wrong version of the dll at runtime, but I don't fully understand how that could be.  I have deleted the 12.0.0.0 dll from my hard drive & still get the exception.

    Wednesday, February 12, 2014 2:10 PM
  • Hi,

    Did you ever sort out this issue?

    Thursday, July 3, 2014 12:51 PM
  • No, unfortunately I haven't had much free time to work on this as other projects trump it for priority.  I'm hoping to be able to get back to it sometime this month, but things have been pretty busy...
    Thursday, July 3, 2014 1:29 PM
  • I ran into the same problem while trying to delete content from a section. The Api always throwed a hrSectionReadOnly (0x8004200b, The section is read-only) or hrPageReadOnly (0x8004200c, The page is read-only).

    Trying to change the readOnly attribute of the section did not work.

    Instead I had to use the .publish method to copy the whole section to another location. Afterwards I used .OpenHierarchy and .GetHierarchy again to load the new file. This time the file was not read-only and I could delete single objects on a page or the whole page itself.

    Deleting the whole section was still not possible. But maybe you could just delete the .one file for this case.








    • Edited by MrTantum Thursday, February 5, 2015 10:57 AM
    Thursday, February 5, 2015 10:56 AM