If you really need to download an xml file as in click on a link and it pops up like a normal file link does then you can Create an UmbracoSurfaceController or UmbracoApiController
And add something like this
public HttpResponseMessage DownloadSitemap()
{
//Generate XML with XMLDocument or something else
//Send the XML to the browser as SteamingContent
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(memorySteamContainingTheXmlFile);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml");
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "sitemap.xml";
return response;
}
Can you create a page that saves as .xml file extension?
Hi,
I want to create an xml sitemap.
I can write the xml structure by creating a template to do this, but can a .xml file be saved?
Thanks!
If by saving you mean save to disk, then my first question would be: Why do you want to do this for a sitemap? Just mark the url in your robots.txt file https://developers.google.com/webmasters/control-crawl-index/docs/robots_txt#sitemap
If you really need to download an xml file as in click on a link and it pops up like a normal file link does then you can Create an UmbracoSurfaceController or UmbracoApiController
And add something like this
docs on surface controllers: https://our.umbraco.org/documentation/reference/routing/surface-controllers
docs on api controllers https://our.umbraco.org/documentation/reference/routing/webapi/
is working on a reply...