<?xml version="1.0"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Find the StartPart</Title>
      <Author>Kevin Boske</Author>
      <Description>Given a file name, find the start part.</Description>
      <Shortcut>FindStartPart</Shortcut>
    </Header>
    <Snippet>
      <References>
        <Reference>
          <Assembly>WindowsBase</Assembly>
          <URL>windowsbase.dll</URL>
        </Reference>
      </References>
      <Imports>
        <Import>
          <Namespace>System.IO</Namespace>
        </Import>
        <Import>
          <Namespace>System.IO.Packaging</Namespace>
        </Import>
        <Import>
          <Namespace>System.Collections.Generic</Namespace>
        </Import>
      </Imports>
      <Code Language="csharp" Kind="method decl">
        <![CDATA[  /// <summary>
        /// Given a file name, find the start part. Works with any Office OpenXML file.
        /// </summary>
        /// <param name="fileName">name of the file to find the start part</param>
        public void FindStartPart(string fileName)
        {
            string officeDocRelType = @"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
            PackagePart documentPart = null;
            Uri documentUri = null;

            //Open the package with Read permission
            using (Package officePackage = Package.Open(fileName, FileMode.Open, FileAccess.Read))
            {
            //Get the start part
                foreach (PackageRelationship relationship in officePackage.GetRelationshipsByType(officeDocRelType))
                {
                // There should only be one document part in the package
                    documentUri = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), relationship.TargetUri);
                    documentPart = officePackage.GetPart(documentUri);
                    break;
                }
                //TODO: Add your code here:
             }
        }
]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>