Welcome to MSDN Blogs Sign in | Join | Help
Using the OpenXmlDocument Class

Now, we can write a small program to use our new class, to dump the relationships to the console:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Examples.LtxOpenXml;

class Program
{
    static void DumpRelationships(List<Relationship> source, int indentLevel)
    {
        string indent = "".PadRight(indentLevel * 2);

        foreach (var r in source)
        {
            Console.WriteLine("{0}Id: {1}",
                indent, r.Id);
            Console.WriteLine("{0}RelationshipType: {1}",
                indent, r.RelationshipType);
            Console.WriteLine("{0}ContentType: {1}",
                indent, r.ContentType);
            Console.WriteLine("{0}SourceUri: {1}",
                indent, r.SourceUri);
            Console.WriteLine("{0}TargetUri: {1}",
                indent, r.TargetUri);
            Console.WriteLine("{0}TargetMode: {1}",
                indent, r.TargetMode);
            if (r.XDocument != null)
                Console.WriteLine("{0}XDocument descendant node count: {1}",
                    indent, r.XDocument.DescendantNodes().Count());
            Console.WriteLine();
            if (r.Relationships != null)
                DumpRelationships(r.Relationships, indentLevel + 1);
        }
    }

    static void Main(string[] args)
    {
        string filename = "OfficeXMLMarkupExplained_en.docx";
        //string filename = "Test.docx";
        //string filename = "Book1.xlsx";

        using (OpenXmlDocument doc = new OpenXmlDocument(filename))
        {
            Console.WriteLine("Document Name: {0}", doc.Name);
            Console.WriteLine();
            DumpRelationships(doc.Relationships, 0);
        }
    }
}

This code produces very similar output to the first example.

Posted: Tuesday, December 11, 2007 5:28 AM by EricWhite
Filed under: ,

Comments

D.K. said:

Theseresourceisforpreparingtheproject,supervisedbyMONOandGOOGLESUMMERCODE2008,Converti...

# March 31, 2008 9:17 AM

cnblogs.com said:

These resource is for preparing the project ,supervised by MONO and GOOGLE SUMMER CODE 2008,Converting

# March 31, 2008 9:19 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker