locked
Reading table of contents from a word file RRS feed

  • Question

  • User735790185 posted

    Hi,

                 I am Navaneeth and new to web development. I have a doubt and hope someone answers my doubt. Here it is. I have a first page with a file uploader and a Ok button. When I select a word file and click the OK button it displays the table of contents of the word file in the second page. I know that there is a feature of creating Table of Contents in a word document automatically. But how do I create Table of Contents for a word file using asp.net(c#). Can someone help me regarding this.?

     Thanks

    Wednesday, September 17, 2008 2:19 AM

All replies

  • User1687629711 posted

    I am assuming you want to create a table of contents in a Word document ... if so this is how you do it 

    http://nishantrana.wordpress.com/2008/07/17/creating-and-updating-table-of-contents-in-word-document-using-c/

    Tuesday, September 23, 2008 12:43 PM
  • User1687629711 posted

    There is also help in MSDN on this topic

     

    http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.tablesofcontents(VS.80).aspx

     private void DocumentTablesOfContents()
    {
        this.Paragraphs[1].Range.InsertParagraphBefore();
        this.Paragraphs[1].Range.InsertParagraphBefore();
        this.Paragraphs[1].Range.Text = "Heading 1";
        this.Paragraphs[2].Range.Text = "Heading 2";

        object Style1 = Word.WdBuiltinStyle.wdStyleHeading1;
        this.Paragraphs[1].set_Style(ref Style1);

        object Style2 = Word.WdBuiltinStyle.wdStyleHeading2;
        this.Paragraphs[2].set_Style(ref Style2);

        object HeadingLevel = 1;
        this.TablesOfContents.Add(this.Application.Selection.Range,
            ref missing, ref HeadingLevel, ref HeadingLevel,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing);
    }

     

    Wednesday, September 24, 2008 6:50 AM