Automated data export

Topics: Core, Customizing Orchard
Jan 23, 2013 at 10:44 AM

Hi guys,

I'm trying to get automated data export working via http. My module is depending on the Import/Export module and I have the following controller:


public ActionResult Export(string[] contenttypes, bool metadata = true, bool settings = true, bool data = true)
	// if no contenttypes asked, export everything
	List<string> contenttypestoexport = contenttypes == null || !contenttypes.Any() ?
		_contentDefinitionManager.ListTypeDefinitions().Select(c => c.Name).ToList() : 
		new List<string>(contenttypes);

	var exportOptions = new ExportOptions { 
		ExportMetadata = metadata, 
		ExportSiteSettings = settings, 
		ExportData = data

	string filepath = _importExportService.Export(contenttypestoexport, exportOptions);
	return new FilePathResult(filepath, "text/xml");

	// TODO delete the file on disk, this needs a change in the importexport module to return the XML feed instead of the filename on disk.


To get this to work nicely I'd like to propose two changes to the Import/Export module. First of all it would be nice to be able to retrieve the XmlDocument itself instead of writing it to file. The interface would look like this:


public interface IImportExportService : IDependency {
	void Import(string recipeText);
	string Export(IEnumerable<string> contentTypes, ExportOptions exportOptions);
	XDocument ExportXml(IEnumerable<string> contentTypes, ExportOptions exportOptions);

Secondly there are hardcoded references to the currently logged in user. I don't need this, the url is publicly available. Could the references to a user be changed to:


_orchardServices.WorkContext.CurrentUser != null ? _orchardServices.WorkContext.CurrentUser.UserName : "Anonymous"


Feb 10, 2013 at 9:40 PM
Looks like a good change, yes. A bug in the issue tracker, with a patch, would be great. Thanks.