/// <summary> /// Writes the element to custom XML part. /// </summary> /// <param name="customXmlPart">The custom XML part.</param> /// <param name="rootElement">The root element.</param> public void WriteElementToCustomXmlPart(CustomXmlPart customXmlPart, XElement rootElement) { if (customXmlPart == null) { throw new ArgumentNullException("customXmlPart"); } if (rootElement == null) { throw new ArgumentNullException("rootElement"); } using (XmlWriter writer = XmlWriter.Create(customXmlPart.GetStream(FileMode.Create, FileAccess.Write))) { rootElement.WriteTo(writer); writer.Flush(); } }
// Generates content of customXmlPart1. private void GenerateCustomXmlPart1Content(CustomXmlPart customXmlPart1) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(customXmlPart1.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8); writer.WriteRaw("<b:Sources SelectedStyle=\"\\APASixthEditionOfficeOnline.xsl\" StyleName=\"APA\" Version=\"6\" xmlns:b=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\" xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\"></b:Sources>\r\n"); writer.Flush(); writer.Close(); }
// Generates content of customXmlPart4. private void GenerateCustomXmlPart4Content(CustomXmlPart customXmlPart4) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(customXmlPart4.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8); writer.WriteRaw("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><b:Sources SelectedStyle=\"\\APA.XSL\" StyleName=\"APA\" xmlns:b=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\" xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\"></b:Sources>"); writer.Flush(); writer.Close(); }
/// <summary> /// Gets the first element from custom XML part. /// </summary> /// <param name="customXmlPart">The custom XML part.</param> /// <param name="elementName">Name of the element.</param> /// <returns></returns> public XElement GetFirstElementFromCustomXmlPart(CustomXmlPart customXmlPart, string elementName) { if (customXmlPart == null) { throw new ArgumentNullException("customXmlPart"); } if (string.IsNullOrEmpty(elementName)) { throw new ArgumentNullException("elementName"); } XDocument customPartDoc = null; using (XmlReader reader = XmlReader.Create(customXmlPart.GetStream(FileMode.Open, FileAccess.Read))) { customPartDoc = XDocument.Load(reader); } XElement element = null; if (customPartDoc != null) { XName elementXName = XName.Get(elementName, this.namespaceUri); element = (from e in customPartDoc.Descendants(elementXName) select e).FirstOrDefault(); } return element; }
// Generates content of customXmlPart3. private void GenerateCustomXmlPart3Content(CustomXmlPart customXmlPart3) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(customXmlPart3.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8); writer.WriteRaw("<?mso-contentType?><FormTemplates xmlns=\"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms\"><Display>DocumentLibraryForm</Display><Edit>DocumentLibraryForm</Edit><New>DocumentLibraryForm</New></FormTemplates>"); writer.Flush(); writer.Close(); }
// Generates content of customXmlPart2. private void GenerateCustomXmlPart2Content(CustomXmlPart customXmlPart2) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(customXmlPart2.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8); writer.WriteRaw("<?xml version=\"1.0\" encoding=\"utf-8\"?><p:properties xmlns:p=\"http://schemas.microsoft.com/office/2006/metadata/properties\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><documentManagement/></p:properties>"); writer.Flush(); writer.Close(); }
// Generates content of customXmlPart1. private void GenerateCustomXmlPart1Content(CustomXmlPart customXmlPart1) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(customXmlPart1.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8); writer.WriteRaw("<?xml version=\"1.0\" encoding=\"utf-8\"?><ct:contentTypeSchema ct:_=\"\" ma:_=\"\" ma:contentTypeName=\"Document\" ma:contentTypeID=\"0x010100DA191A7983F9F44A9C60D24B5C4D22D7\" ma:contentTypeVersion=\"1\" ma:contentTypeDescription=\"Create a new document.\" ma:contentTypeScope=\"\" ma:versionID=\"221a530deb90796bf295783ddced7382\" xmlns:ct=\"http://schemas.microsoft.com/office/2006/metadata/contentType\" xmlns:ma=\"http://schemas.microsoft.com/office/2006/metadata/properties/metaAttributes\">\r\n<xsd:schema targetNamespace=\"http://schemas.microsoft.com/office/2006/metadata/properties\" ma:root=\"true\" ma:fieldsID=\"3c34477644e5086b93ec9184c3231c1e\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:p=\"http://schemas.microsoft.com/office/2006/metadata/properties\">\r\n<xsd:element name=\"properties\">\r\n<xsd:complexType>\r\n<xsd:sequence>\r\n<xsd:element name=\"documentManagement\">\r\n<xsd:complexType>\r\n<xsd:all/>\r\n</xsd:complexType>\r\n</xsd:element>\r\n</xsd:sequence>\r\n</xsd:complexType>\r\n</xsd:element>\r\n</xsd:schema>\r\n<xsd:schema targetNamespace=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\" blockDefault=\"#all\" xmlns=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:odoc=\"http://schemas.microsoft.com/office/internal/2005/internalDocumentation\">\r\n<xsd:import namespace=\"http://purl.org/dc/elements/1.1/\" schemaLocation=\"http://dublincore.org/schemas/xmls/qdc/2003/04/02/dc.xsd\"/>\r\n<xsd:import namespace=\"http://purl.org/dc/terms/\" schemaLocation=\"http://dublincore.org/schemas/xmls/qdc/2003/04/02/dcterms.xsd\"/>\r\n<xsd:element name=\"coreProperties\" type=\"CT_coreProperties\"/>\r\n<xsd:complexType name=\"CT_coreProperties\">\r\n<xsd:all>\r\n<xsd:element ref=\"dc:creator\" minOccurs=\"0\" maxOccurs=\"1\"/>\r\n<xsd:element ref=\"dcterms:created\" minOccurs=\"0\" maxOccurs=\"1\"/>\r\n<xsd:element ref=\"dc:identifier\" minOccurs=\"0\" maxOccurs=\"1\"/>\r\n<xsd:element name=\"contentType\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xsd:string\" ma:index=\"0\" ma:displayName=\"Content Type\" ma:readOnly=\"true\"/>\r\n<xsd:element ref=\"dc:title\" minOccurs=\"0\" maxOccurs=\"1\" ma:index=\"4\" ma:displayName=\"Title\"/>\r\n<xsd:element ref=\"dc:subject\" minOccurs=\"0\" maxOccurs=\"1\"/>\r\n<xsd:element ref=\"dc:description\" minOccurs=\"0\" maxOccurs=\"1\"/>\r\n<xsd:element name=\"keywords\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xsd:string\"/>\r\n<xsd:element ref=\"dc:language\" minOccurs=\"0\" maxOccurs=\"1\"/>\r\n<xsd:element name=\"category\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xsd:string\"/>\r\n<xsd:element name=\"version\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xsd:string\"/>\r\n<xsd:element name=\"revision\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xsd:string\">\r\n<xsd:annotation>\r\n<xsd:documentation>\r\n This value indicates the number of saves or revisions. The application is responsible for updating this value after each revision.\r\n </xsd:documentation>\r\n</xsd:annotation>\r\n</xsd:element>\r\n<xsd:element name=\"lastModifiedBy\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xsd:string\"/>\r\n<xsd:element ref=\"dcterms:modified\" minOccurs=\"0\" maxOccurs=\"1\"/>\r\n<xsd:element name=\"lastPrinted\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xsd:dateTime\"/>\r\n<xsd:element name=\"contentStatus\" minOccurs=\"0\" maxOccurs=\"1\" type=\"xsd:string\"/>\r\n</xsd:all>\r\n</xsd:complexType>\r\n</xsd:schema>\r\n</ct:contentTypeSchema>"); writer.Flush(); writer.Close(); }
internal void FeedDataCustomXmlPart(CustomXmlPart NewPart, CustomXmlPart ExistingPart) { using (StreamReader sr = new StreamReader(ExistingPart.GetStream())) { using (StreamWriter sw = new StreamWriter(NewPart.GetStream(FileMode.Create))) { sw.Write(sr.ReadToEnd()); } } if (ExistingPart.CustomXmlPropertiesPart != null) { NewPart.AddNewPart<CustomXmlPropertiesPart>(ExistingPart.GetIdOfPart(ExistingPart.CustomXmlPropertiesPart)); using (StreamReader sr = new StreamReader(ExistingPart.CustomXmlPropertiesPart.GetStream())) { using (StreamWriter sw = new StreamWriter(NewPart.CustomXmlPropertiesPart.GetStream(FileMode.Create))) { sw.Write(sr.ReadToEnd()); } } } }
// Generates content of customXmlPart1. private void GenerateCustomXmlPart1Content(CustomXmlPart customXmlPart1) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(customXmlPart1.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8); writer.WriteRaw("<?xml version=\"1.0\" encoding=\"utf-8\"?><Root><Name>Eric White</Name><Company>Microsoft Corporation</Company><Address>One Microsoft Way</Address><City>Redmond</City><State>WA</State><Country>USA</Country><PostalCode>98052</PostalCode></Root>"); writer.Flush(); writer.Close(); }