Making pages easier to sync with a mobile device


I was thinking of a tool to somehow send selected pages from my different OneNote notebooks to my Windows Mobile phone and went to talk with Dan Escapa (http://blogs.msdn.com/descapa) about some design choices I was facing. He was working on a very similar tool and gave me his code to finish. Nice – saved me a bunch of time.


   


His design was much simpler than mine. He added a toolbar button to copy the currently viewed page to the OneNote Mobile folder when clicked. My design was much more embarrassingly clunky and I scrapped it in favor of finishing his addin.


   


If you want, you can get the setup files and source code from these links: 


Updated setup link at http://johnguin.web.officelive.com/Documents/CopyToONMobile_Setup.zip  (March 1, 2010) 


Setup files: http://johnguin.members.winisp.net/Shared%20Documents/CopyToONMobile_Setup.zip


(Edit: looks like WinISP got swamped very quickly.  Here is an alternate download site: http://johnguin.com/Documents/CopyToONMobile_Setup.zip)


   


Code (C#): http://johnguin.members.winisp.net/Shared%20Documents/CopyToONMobile_Source.zip


If you need the code, email me.  I’ll try to restore the partial archive I have and retrieve it.   


To install, as usual, exit OneNote and run the setup.exe. You will get a button to copy the currently viewed page to the ON Mobile folder. Makes life a little bit easier.


   


And if you click the button twice, you will discover a “feature” I added which Dan did not like. I create a simple XML file to track the GUIDs of pages already copied so you won’t get duplicates on the device. Dan wanted to keep it simple and just always make a new copy. To get his original behavior, you can select to never show that dialog again and make a copy always.


   


The log file (copytoonenotemobile.xml) resides in the local settings\app data folder if you want to look at it. It also logs any errors you may hit as comments. Deleting that file will cause the addin to “forget” what has already been copied.


   


Next up, I’ll go through some of the bugs found when testing this addin. Let me know if you find more.

Comments (35)

  1. Keith Ryde says:

    Can’t make the links to the downloads work.

  2. I wanted to post about a new powertoy that John Guin and I worked on called "Send to mobile device".

  3. JohnGuin says:

    The server seems to be under heavy load right now.  this is what I get for trying to use nothing but free servers…

    All I can suggest is waiting and trying again in a bit.

    John

  4. tam says:

    Once I’ve run the setup file, where do I find the icon in onenote please? (have searched everywhere but cannot see it)  Thanks for your help.

  5. JohnGuin says:

    The button should be on the far right of the standard toolbar.  If you try to customize the toolbar, does "Copy to Device" show?

    John

  6. Raj says:

    I still not able to see the button :(

    Customize toolbar does not show up either…

    I tried uninstalling and reinstalling the app. No luck at all.

  7. Dave Kolb says:

    Is there some decent API doc on the COM object model anywhere? I have not been able to find. If so could someone send me a link at dave@DotNetCodeSlingers.com as it may be a while before I find my way back here. Thanks, Dave

  8. Dave Kolb says:

    P.S. The first addin I installed I could not find either until I found that I had addins disabled in the options menu and then restarted ON. Bet is your problem. Dave

  9. Egypt says:

    Mine isn’t working either… it shows nowhere. I’ve checked add-ins as well, and its enabled (however, the addins list is empty, meaning copy2device doesn’t even exist on it!). So what’s the problem? Is there a specific way to install this? (and what do i do  with the code folder..?)

  10. JohnGuin says:

    First, make sure OneNote has the .NET programmability support installed (it does not install by default).  In your control panel, go to Programs or Add/Remove Programs and rerun setup for OneNote.  When you select a Custom install, you will get a tree view that will show you the option under OneNote to install .NET programmability support.

    Install it, then reinstall the Copy To Device addin.

    The code folder is only for people who want to see the code I wrote.  If you don’t want that folder, you can delete it.

    Sorry for the problems,

    John

  11. Egypt says:

    i restarted my laptop again n now the button shows; thx anyways though… however, ever since i installed the Copy2Device addin, my pics won’t open =S completely random but yeah… it gives me the pic’s folder path and tells me it’s not compatible with Win32 =S ( i have to right click > open with > [..] every single picture!!)

    that a bug?

  12. JohnGuin says:

    Sounds like something went wrong somewhere.  I suggest copying the exact error message and looking that up on the internet.  either that or double check file associations (open a folder and click file folder properties file types, on WinXP.  On vista, right click the image file and select Properties.  There is a button for Opens With – change it to open with whatever image viewer you want to use.  I use Paint).

    Hope this helps, and sorry for the problems,

    John

  13. I’ve tried to keep this up to date twice a week since I started. Like most other people who run blogs,

  14. FamDoc says:

    I have been able to install the powertool, but it does not copy when the menu button is pressed.  I installed other powertools and they work, but this does not.  Suggestions.

  15. John says:

    Can you look in local settingsapp data folder for a file named CopyToOneNoteMobile.xml?  That is a log of what happens when you run the tool.  Can you either post it here or send it to me via email and I’ll take a look.

    Also, I assume you have successfully synced with your mobile phone already, and other than this powertoy, sync with OneNote works as expected, right?

    Thanks and sorry for the problems,

    John

  16. Kal says:

    This is a cool feature, John.  Is there any way to make the data sync BACK to the original source if you change it in OneNote Mobile?  

    In a perfect world, I’d like data to sync across devices/platforms in OneNote just as it does between my desktops and laptops now (with a little assist from Hamachi.)

    Thanks, Kal

  17. JohnGuin says:

    Hi Kal,

    There is no easy way to keep the data in sync with this powertoy.  I would need to re-write an entire sync mechanism to see if that data has changed on BOTH pages, and that is not a trivial task.

    We are working on improving the experience.

    Thanks for using OneNote,

    John

  18. TechMarketer says:

    I would love for this tool to work. Unfortunately I’m having a similar problem to the one FamDoc reported above: once clicked, the "Copy to Mobile" button 1) always stays grayed out and 2) fails to copy the page.

  19. John says:

    Hello,

    can you try this:  make sure OneNote has the .NET programmability support installed (it does not install by default).  In your control panel, go to Programs or Add/Remove Programs and rerun setup for OneNote.  Select a Change install and you will get a tree view that will show you the option under OneNote to install .NET programmability support.  Enable it, finish setup and then reboot.  

    Let me know if that fixes the problem,

    John

  20. TechMarketer says:

    Dude, it worked! 100% functional now. Wow this is an amazing add-on… absolutely convenient!

    Thanks so much John!

  21. clamshell says:

    This is a really nice add-in, I’ve been looking for something like this. A couple of suggestions:

    Running on Windows XP (Tablet PC Edition), the dialog for overwriting the note came up behind the OneNote window. I clicked the button several times before I realized this. It would be nicer if it showed up in front.

    When clicked on a note in my OneNote Mobile notebook that had already been copied, it automatically creates another copy in that same notebook. Shouldn’t the button be disabled, or cause it to be copied back to it’s original location?

    I second Kal’s request for a more advanced syncing process. As I understand how complex that is, how about another option in the "overwrite" dialog for copying the OneNote Mobile page back to the main notebook.

  22. clamshell says:

    Oops. Hit submit before my fourth suggestion:

    Some way to automatically copy all notes mentioned in your XML file to OneNote Mobile at once.

  23. JohnGuin says:

    Hi Clamshell,

    1.  I wish I could solve the focus problem.  I’ve tried forcing my dialog to have focus, but if some other application takes focus right after mine, it fails again.

    2.  Duplicate pages should be created – can you look in the install folder and email me the log files you find there?

    3.  We’re working on Mobile improvements.  Stay tuned.

    4.  I don’t understand this request – can you clarify what you mean by "copying all notes in the XML file?"  The XML file lists all the notes you have already copied in order to prevent them from being duplicated.  Deleting this file will allow duplicates to be created since the list of files you have already copied will disappear.  In other words, if you see a page in this file, it should already be in the mobile device folder.

  24. JohnGuin says:

    Hi Clamshell,

    1.  I wish I could solve the focus problem.  I’ve tried forcing my dialog to have focus, but if some other application takes focus right after mine, it fails again.

    2.  Duplicate pages should be created – can you look in the install folder and email me the log files you find there?

    3.  We’re working on Mobile improvements.  Stay tuned.

    4.  I don’t understand this request – can you clarify what you mean by "copying all notes in the XML file?"  The XML file lists all the notes you have already copied in order to prevent them from being duplicated.  Deleting this file will allow duplicates to be created since the list of files you have already copied will disappear.  In other words, if you see a page in this file, it should already be in the mobile device folder.

  25. Mal Evans says:

    Looks like a great add-in now that I have ON sync working

    Links do not appear to be working any longer… :(

  26. JohnGuin says:

    Make sure you use the link to http://johnguin.com/Documents/CopyToONMobile_Setup.zip

    The server hosting the other files got decommissioned and I’m still trying to restore from backups.

    Sorry for the problems.

  27. Tom Hodgers says:

    Hi John.

    Do you have an up to date link for downloading the CopyToONMobile_Setup.zip file.

    Many thanks.

    Tom

  28. JohnGuin says:

    Updated the link.  Sorry for the problems.

  29. Tom Hodgers says:

    Many thanks for the swift reply John.

    I have recently installed Office 2010 beta on my laptop.

    Do you have any info about the OneNote Mobile 2010 Beta?

    From what I`ve seen, surfing today (all day):

    1. It`s only available for Windows Mobile 6.5

    2. Ìt`s also available for WM 6.x

    3. It won`t work with WM 7.0

    4. It will work with WM 6 to 7

    5. It doesn`t work

    6. According to Microsoft, it`s available from Windows Marketplace for Mobile (but it isn`t, I tried most of the day to download – all links dead)

    7. It will download only for certain geographical regions

    8. There exists a "hack" for downloading from anywhere

    9. After terminating it`s natural life in April 2010 it will stop working and anyone who had the bought version of ON Mobile 2007 installed will have to re-install.

    Could you shed us some light on this matter?

    Thanks again,

    Tom

  30. quenclab says:

    I would like to get your source code if you are still giving it out… i have been using this addin for a while and have been writing my own to copy all pages from select notebooks to the mobile section… I think you may have what I need to finish it. Thanks Quentin

  31. JohnGuin says:

    I would gladly give it out, but I lost the hard drive that had the backup copy after the server that was hosting it went down…Extremely sorry and embarrassed.

  32. quenclab says:

    Thanks for the reply… Sorry to hear that… I can figure out how to enumerate through all the filter which notebooks notebooks I want to sync and pull out the individual pages. I can create a new page in the mobile section but am unable to get the page copied there… I have downloaded the source code to your onenote text importer but cannot figure it out. Can you help?

    Where I am getting stuck is

    onenoteApp.CreateNewPage(mobileSectionID, out copyPageID, NewPageStyle.npsBlankPageWithTitle);

    onenoteApp.UpdatePageContent(strPage, DateTime.MinValue);

    strPage contains the xml string from the GetPageContent. I have tried updating ID attribute through xDocument to "u0022{1}u0022" as in your text importer source code but it fails with an invalid xml error.

    How do you update get the new ID so it will save the changes the new page you created in the mobile Section? I can post my whole source code if you like.

  33. JohnGuin says:

    Sure – post the code (and the xml you are using wiht UpdatePageContent) and I can take a look.

  34. quenclab says:

    Maybe I am taking the wrong approach… I just want to copy pages out of a section and insert them in the mobile phone section. If i comment out "pageXML.Element(nsone + "Page").Attribute("ID").Value = newNoteID;" the code will run but is evidently just updating the existing pages. My new pages that was created under the mobile section are blank. If I uncomment the line it fails with a HResult error code 0x80042001 which is an invalid xml error.

    Your help is greatly appreciated.

    Here is the code:

    using System;

    using System.IO;

    using System.Linq;

    using System.Xml.Linq;

    using Microsoft.Office.Interop.OneNote;

    class Program

    {

       static void Main(string[] args)

       {

           var onenoteApp = new Application();

           string notebookXml;

           //string[] notebooks = new string[5] {"HowTo","Work Notebook","Projects","Home Notebook","Church"};

           string[] notebooks = new string[1] { "Test"};

           onenoteApp.GetHierarchy(null, HierarchyScope.hsPages, out notebookXml);

           StreamWriter writer = new StreamWriter("notebook.xml");

           var doc = XDocument.Parse(notebookXml);

           var ns = doc.Root.Name.Namespace;

           string mobileSectionID = "";

           foreach (var sectionNode in from node in doc.Descendants(ns + "Section") select node)

           {

               //Console.WriteLine(sectionNode.Attribute("name").Value + " = Notes from HTC-ST6356");

               if (sectionNode.Attribute("name").Value == "Notes from HTC-ST6356")

               {

                   mobileSectionID = sectionNode.Attribute("ID").Value;

                   //Console.WriteLine("found" + mobileSectionID);

               }

           }

           foreach (var notebookNode in from node in doc.Descendants(ns + "Notebook") select node)

           {

               if (notebooks.Contains(notebookNode.Attribute("name").Value))

               {                

                   writer.WriteLine(notebookNode.Attribute("name").Value);

                   foreach (var sectionNode in from node in notebookNode.Descendants(ns + "Section") select node)

                   {

                       writer.WriteLine("    " + sectionNode.Attribute("name").Value);

                       foreach (var pageNode in from node in sectionNode.Descendants(ns + "Page") select node)

                       {

                           writer.WriteLine("        " + pageNode.Attribute("name").Value);

                           string strPage;

                           onenoteApp.GetPageContent(pageNode.Attribute("ID").Value, out strPage);

                           string newNoteID = "u0022{1}u0022";

                           var pageXML = XDocument.Parse(strPage);

                           XNamespace nsone = "schemas.microsoft.com/…/onenote";

                           pageXML.Element(nsone + "Page").Attribute("ID").Value = newNoteID;

                           string copyPageID;

                           writer.WriteLine(pageXML.ToString());

                           strPage = pageXML.ToString();

                           onenoteApp.CreateNewPage(mobileSectionID, out copyPageID, NewPageStyle.npsBlankPageWithTitle);

                           onenoteApp.UpdatePageContent(strPage, DateTime.MinValue);

                       }

                   }

               }

           }

           writer.Close();

           Console.ReadKey();

       }

    }

    Here is the xml from the GetPageContent retrieves:

    <one:Page xmlns:one="schemas.microsoft.com/…/onenote" ID="{F7E295CF-0DCA-451E-B1C5-9A293E4706F1}{1}{B0}" name="Use this notebook to keep your research organized" dateTime="2006-05-22T20:19:21.000Z" lastModifiedTime="2011-02-17T18:35:35.000Z" pageLevel="1" lang="en-US">

     <one:QuickStyleDef index="0" name="p" fontColor="automatic" highlightColor="automatic" font="Calibri" fontSize="11.0" spaceBefore="0.0" spaceAfter="0.0" />

     <one:PageSettings RTL="false" color="automatic">

       <one:PageSize>

         <one:Automatic />

       </one:PageSize>

       <one:RuleLines visible="false" />

     </one:PageSettings>

     <one:Title showDate="false" showTime="false" lang="en-US">

       <one:OE author="Quentin Claborn" authorInitials="QC" lastModifiedBy="Quentin Claborn" lastModifiedByInitials="QC" creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{68}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Cambria;font-size:17.0pt">

         <one:T><![CDATA[Use this notebook to keep your research organized]]></one:T>

       </one:OE>

     </one:Title>

     <one:Image format="png" backgroundImage="true" originalPageNumber="0" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{14}{B0}">

       <one:Position x="-2.999954223632812" y="0.149999856948853" z="0" />

       <one:Size width="1004.228271484375" height="143.4984741210937" isSetByUser="true" />

       <one:CallbackID callbackID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{14}{B0}" />

     </one:Image>

     <one:Outline author="Quentin Claborn" authorInitials="QC" lastModifiedBy="Quentin Claborn" lastModifiedByInitials="QC" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{16}{B0}">

       <one:Position x="36.0" y="86.4000015258789" z="1" />

       <one:Size width="435.9750366210937" height="289.4820556640625" />

       <one:Indents>

         <one:Indent level="2" indent="36.0" />

         <one:Indent level="3" indent="36.0" />

       </one:Indents>

       <one:OEChildren>

         <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{17}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

           <one:T><![CDATA[You can collect all information for all of your research projects in one notebook or create a new research notebook for each project. ]]></one:T>

         </one:OE>

         <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{22}{B0}" alignment="left" quickStyleIndex="0">

           <one:T><![CDATA[]]></one:T>

         </one:OE>

         <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{25}{B0}" alignment="left" quickStyleIndex="0">

           <one:T style="font-family:Constantia;font-size:11.0pt"><![CDATA[<span

    style='font-weight:bold'>Ideas for using this notebook</span>]]></one:T>

           <one:OEChildren>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{27}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[Organize notes on research activities]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{30}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[Keep a to-do list of your current work items]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{33}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[Manage information you collect from other research papers  ]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{36}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[Take meeting notes]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{39}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[Record ideas and questions]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{42}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[Keep notes on experiments and interviews]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{45}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[Develop outlines for research papers]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{48}{B0}" alignment="left" quickStyleIndex="0">

               <one:T><![CDATA[]]></one:T>

             </one:OE>

           </one:OEChildren>

         </one:OE>

         <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{51}{B0}" alignment="left" quickStyleIndex="0">

           <one:T style="font-family:Constantia;font-size:11.0pt"><![CDATA[<span

    style='font-weight:bold'>Tips</span>]]></one:T>

           <one:OEChildren>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{53}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[To move items from one section or notebook to another, select the information and <span

    style='font-weight:bold'>drag and drop</span> it into the new location. ]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{57}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[Need to<span

    style='font-weight:bold'> take a quick note</span>? Press the <span

    style='font-weight:bold'>Windows Logo Key</span> + <span style='font-weight:

    bold'>N</span> to bring up a new side note window where you can take notes like you do on a sticky note. These notes are stored in your Unfiled Notes section, and you can drag and drop them to the appropriate section.]]></one:T>

             </one:OE>

             <one:OE creationTime="2011-02-17T18:34:44.000Z" lastModifiedTime="2011-02-17T18:34:44.000Z" objectID="{D4E734AC-6C7C-428B-A983-9E4091D91659}{61}{B0}" alignment="left" quickStyleIndex="0" style="font-family:Constantia;font-size:11.0pt">

               <one:List>

                 <one:Bullet bullet="1" fontSize="11.0" />

               </one:List>

               <one:T><![CDATA[This section is just to get you started. Right-click the Start here section tab and click Delete to remove this section at any time.]]></one:T>

             </one:OE>

           </one:OEChildren>

         </one:OE>

       </one:OEChildren>

     </one:Outline>

    </one:Page>

  35. John says:

    2 things jump out.

    1. Try to remove the ID parameters from the new page you are creating.  ON will assign IDs and this generally works much better.

    2. You have an IMAGE node, but no binary data for it.  Try call GetPageContent with piAll as the type of data to get so you will have it when you create the new page.