Copied to clipboard

Flag this post as spam?

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


  • Alex Gill 26 posts 61 karma points
    Dec 02, 2013 @ 18:10
    Alex Gill
    0

    Creating new Template clears content of file

    I want to programatically create and save a new Template using an existing .cshtml file. When I call

    var template = new Template(path, name, alias);
    _fileService.SaveTemplate(template);
    

    the template is added to Umbraco, but the content of the template is missing!

    A workaround that I can use is to copy the contents of the file before creating the template and then set it using the Content property:

    var absPath = HttpContext.Current.Server.MapPath(Path.Combine("~", "Views", path));
    var content = System.IO.File.ReadAllText(absPath);
    var template = new Template(path, name, alias) { Content = content };
    

    But ideally I don't want to do that!

    Any ideas?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies