Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Damon 217 posts 287 karma points
    May 26, 2017 @ 12:39
    Damon
    0

    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!

  • Sven Geusens 169 posts 881 karma points c-trib
    May 30, 2017 @ 14:18
    Sven Geusens
    0

    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

    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;
    }
    

    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/

Please Sign in or register to post replies

Write your reply to:

Draft