internal static string Serialize(Exporter exporter, ContentItem item) { using (var sw = new StringWriter()) { exporter.Export(item, ExportOptions.ExcludePages | ExportOptions.ExcludeAttachments, sw); return sw.ToString(); } }
public ActionResult Item(int id) { var item = _repository.Get(id); if (item != null) try { var itemXmlWriter = new ItemXmlWriter(Context.Current.Definitions, null, null); var exporter = new Exporter(itemXmlWriter); var ms = new MemoryStream(); var tw = new StreamWriter(ms); { exporter.Export(item, ExportOptions.ExcludeAttachments | ExportOptions.ExcludePages, tw); } ms.Position = 0; return new FileStreamResult(ms, "application/xml"); } catch (Exception ex) { return Content(ex.Message, "text/plain"); } return new EmptyResult(); }
public void ExportItem(ContentItem item) { // no UrlParser and FS -> cannot export Attachments var itemXmlWriter = new ItemXmlWriter(_definitions, null, null); var exporter = new Exporter(itemXmlWriter); var path = _path + '/' + GetContentItemFilenameUnique(item.ID); using (var ms = new MemoryStream()) { using (var tw = new StreamWriter(ms)) { lock (_syncLock) { // Nhibernate doesn't like parallel ? exporter.Export(item, ExportOptions.ExcludeAttachments | ExportOptions.ExcludePages, tw); } // Save to FS ms.Position = 0; _fs.WriteFile(path, ms, item.Published); } } }