public void UpdateXmlDocument(XmlDocument document, string path) { using (MemoryStream outContentStream = new MemoryStream()) { XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = false; xmlSettings.NewLineChars = String.Empty; using (XmlWriter xmlWriter = XmlWriter.Create(outContentStream, xmlSettings)) document.Save(xmlWriter); odtZip.BeginUpdate(); StreamStaticDataSource sds = new StreamStaticDataSource(); sds.SetStream(outContentStream); odtZip.Add(sds, path); odtZip.CommitUpdate(); } }
public void AddFile(byte[] data, string path) { XmlDocument manifest = GetXMLDocument("META-INF/manifest.xml"); XmlNamespaceManager nsManager = new XmlNamespaceManager(manifest.NameTable); nsManager.AddNamespace("manifest", "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"); XmlNode manifestNode = manifest.SelectSingleNode("/manifest:manifest", nsManager); XmlElement fileEntry = manifest.CreateElement("manifest", "file-entry", nsManager.LookupNamespace("manifest")); fileEntry.SetAttribute("full-path", nsManager.LookupNamespace("manifest"), path); fileEntry.SetAttribute("media-type", nsManager.LookupNamespace("manifest"), "image/png"); manifestNode.AppendChild(fileEntry); using (var fileStream = new MemoryStream(data)) { odtZip.BeginUpdate(); StreamStaticDataSource sds = new StreamStaticDataSource(); sds.SetStream(fileStream); odtZip.Add(sds, path); odtZip.CommitUpdate(); } UpdateXmlDocument(manifest, "META-INF/manifest.xml"); }
public void AddFile(byte[] data, string path) { XmlDocument manifest = GetXMLDocument ("META-INF/manifest.xml"); XmlNamespaceManager nsManager = new XmlNamespaceManager (manifest.NameTable); nsManager.AddNamespace ("manifest", "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"); XmlNode manifestNode = manifest.SelectSingleNode("/manifest:manifest",nsManager); XmlElement fileEntry = manifest.CreateElement ("manifest", "file-entry", nsManager.LookupNamespace("manifest")); fileEntry.SetAttribute ("full-path", nsManager.LookupNamespace ("manifest"),path); fileEntry.SetAttribute ("media-type", nsManager.LookupNamespace ("manifest"), "image/png"); manifestNode.AppendChild(fileEntry); using (var fileStream = new MemoryStream (data)) { odtZip.BeginUpdate (); StreamStaticDataSource sds = new StreamStaticDataSource (); sds.SetStream (fileStream); odtZip.Add (sds, path); odtZip.CommitUpdate (); } UpdateXmlDocument (manifest, "META-INF/manifest.xml"); }
public void UpdateXmlDocument(XmlDocument document, string path) { using( MemoryStream outContentStream = new MemoryStream ()) { XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = false; xmlSettings.NewLineChars = String.Empty; using (XmlWriter xmlWriter = XmlWriter.Create (outContentStream, xmlSettings)) document.Save (xmlWriter); odtZip.BeginUpdate (); StreamStaticDataSource sds = new StreamStaticDataSource (); sds.SetStream (outContentStream); odtZip.Add (sds, path); odtZip.CommitUpdate (); } }