Search code examples
umbraco

Umbraco 4 FileService


Ok as the name stated Umbraco 4 Fileservice, but I dont think FileService works on umbraco 4.

I have an Umbraco 4 project where I need to get all my templates, I need to extract their name, aliases, parent template and the content for personal use, but I dont know how to get all of them, in Umbraco 6 and 7 it was easy using FileService but I am on Umbraco 4.

I hope somebody here can help me to do this in Umbraco 4, because I really need to get all those templates, not only templates but also some items like macroscripts.

(please dont advise about creating packages I dont want to use that)

Thanks a lot


Solution

  • If you can't/won't use uSync, you'll need to write your own code to do it. The FileService was introduced in 6 I think, so it doesn't work in 4.

    To get all of the templates in code, you would do something like this:

    var templates = umbraco.cms.businesslogic.template.Template.GetAllAsList();
    
    foreach (var item in templates)
    {
        //template alias
        item.Alias;
        //parent id
        item.ParentId;
        //the path to the master file so you can get using system.io
        item.TemplateFilePath;
        //the name of the template
        item.Text;
    }