/// <summary> /// Exports the pages of site including their history as a single XML file. /// </summary> /// <returns>A <see cref="FileStreamResult"/> called 'roadkill-export.xml' containing the XML data. /// If an error occurs, a <see cref="HttpNotFound"/> result is returned and the error message written to the trace.</returns> public ActionResult ExportAsXml() { try { PageManager manager = new PageManager(); string xml = manager.ExportToXml(); // Let the FileStreamResult dispose the stream MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); writer.Write(xml); writer.Flush(); stream.Position = 0; FileStreamResult result = new FileStreamResult(stream, "text/xml"); result.FileDownloadName = "roadkill-export.xml"; return result; } catch (IOException e) { Log.Warn(e, "Unable to export as XML"); TempData["Message"] = string.Format(SiteStrings.SiteSettings_Tools_ExportXml_Error, e.Message); return RedirectToAction("Tools"); } }