0

I have came up with the following code:

static void Main(string[] args)
{
    Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
    object miss = System.Reflection.Missing.Value;
    object path = @"C:\\Users\\t-aaalle\\Documents\\TesterWordAddin.docx";
    object readOnly = true;

    Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(
        ref path, ref miss, ref readOnly,
        ref miss, ref miss, ref miss, ref miss, ref miss, ref miss,
        ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);

    string totalText = "";

    for (int i = 0; i < docs.Paragraphs.Count; i++)
    {
        totalText += "\r\n" + docs.Paragraphs[i + 1].Range.Text.ToString();
    }

    Console.WriteLine(totalText);
    Console.ReadLine();
    docs.Close();
    word.Quit();
}

Currently this reads the text that is in a Microsoft word file, and what I want is to be able to take the variable 'totalText' and have that value stored in an OneNote file. Is there any C# librarys, or classes that will help me in doing this, perhaps stackoverflow posts that I might have missed?

Thanks

  • Here is a question that could be helpful to you: https://stackoverflow.com/questions/27294510/how-to-write-to-a-onenote-2013-page-using-c-sharp-and-the-onenote-interop – Capn Jack Jul 25 '17 at 19:28
  • Thanks I will be sure to check this out –  Jul 25 '17 at 19:32

1 Answers1

0

Your code related to reading the content of Word documents may be interesting, but unless you have some problem with that code it is entirely irrelevant to your problem of how to access/update a OneNote notebook.

For that, it sounds like what you need is an API for accessing/updating OneNote and, fortunately, the search term OneNote API is recognised by popular search engines such as Google. ;)

In case you are having trouble accessing Google for some reason, this link will take you directly to the Microsoft OneNote Developer Center

If you subsequently have trouble achieving what you need using the OneNote API itself you could then post a new, specific question about that problem, if/when it arises.

Deltics
  • 22,162
  • 2
  • 42
  • 70
  • Well what I am trying to do is take a word document and have it's contents converted into a onenote file... the purpose for the code I now realize isn't relevant to the question because I was just testing to see if I could get the text from a microsoft word document lol thanks for the insight :) –  Jul 25 '17 at 19:39