Hey guys so in my program I'm working on I need to open /word/theme/theme1.xml
I have attempted to do this using the following code...
//open package
package = System.IO.Packaging.Package.Open(fileName, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
// get document.xml (changed to app.xml)
foreach (System.IO.Packaging.PackageRelationship relationship in package.GetRelationshipsByType(docRelationship))
{
//Set up Uri
Uri documentUri = System.IO.Packaging.PackUriHelper.ResolvePartUri(relationship.SourceUri, relationship.TargetUri);
docPart = package.GetPart(documentUri);
break;
}
//work with actuall document
doc = new XmlDocument();
doc.Load(docPart.GetStream());
docRelationship is set to "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" which is the relationship for theme/theme1.xml in /word/_rels/document.xml.rels, but when i complile the code I get null reference on "doc.Load(docPart.GetStream())" for docPart. Not I use this same code with a diffrent docRelationship to open document.xml a few lines above this and it works fine so I'm not sure what I am doing wrong here. Thanks for the help guys.
I just had an idea while I was typing this up, could it be because i have opened a package with the relationship to document.xml first, closing it and then trying to open another one to theme1.xml? should I just use the first package I created? I'm not sure how to tell it to go from that packagePart to theme1.xml though.