Copied to clipboard

Flag this post as spam?

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


  • Amadeu Antunes 7 posts 79 karma points
    Sep 04, 2019 @ 13:11
    Amadeu Antunes
    0

    How to get html generated by razor into a string?

    I created a workflow using umbraco and what I am trying to do is: create a workflow that get the html created by a razor template (umbraco.forms).

    Here is the locations where is the templates of umbraco.forms

    Views\Partials\Forms\Emails This template is what I want to send by email when this workflow is called.

    public class SendMail : WorkflowType
    {  
        //Here I get the path where the razor template is
        [Umbraco.Forms.Core.Attributes.Setting("Path to template",
         Description = "Path to template",
         View = "TextField")]
         public string Template{ get; set; }
       public SendMail()
       {
    
        this.Id = new Guid("ccbeb0d5-adaa-4729-8b4c-4bb439dc0204");
        this.Name = "Send Mail";
        this.Description = "Send Mail";
        this.Icon = "icon-plugin";
        this.Group = "Services";
       }
        //When workflow get called this method is executed 
        public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
       {
    
          //here I'm trying to get the template converted to string however isn't work
         //  string template = html.Raw(Template).ToString();
       }
    
    }
    

    I tried string template = html.Raw(Template); but I have no access to the html.Raw("");

    I've tried this solutions but seems that record.ParseWithRazorView(filePath); doesn't exists

    There is a workflow that do something close but seems I can't re-write or get access to this code enter image description here

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Sep 07, 2019 @ 06:43
    Shaishav Karnani from digitallymedia.com
    1

    Hi Amadeu,

    You can get the template to string by calling this code. You don't require Html.Raw here.

    string text = File.ReadAllText(Server.MapPath(template), Encoding.UTF8);
    

    Regards,

    Shaishav

  • Amadeu Antunes 7 posts 79 karma points
    Sep 09, 2019 @ 08:13
    Amadeu Antunes
    0

    Hi Shaishav Karnani,

    Seems that I can't find the method ReadAllText()

  • Jonathan Distenfeld 105 posts 618 karma points
    Sep 09, 2019 @ 11:04
    Jonathan Distenfeld
    1

    Hi Amadeu,

    have you referenced the namespace System.IO?

    string text = System.IO.File.ReadAllText(Server.MapPath(template), Encoding.UTF8);
    

    ~ Jonathan

  • Amadeu Antunes 7 posts 79 karma points
    Oct 05, 2019 @ 23:03
    Amadeu Antunes
    1

    I created a View and a umbraco controller

    namespace name.Core.Controllers
    {
        public class TemplateController : Umbraco.Web.Mvc.SurfaceController
        {
            public ActionResult Template()
            {
    
                return View();
            }
       }
    }
    

    The I pass the URL into "pathtoTemplate"

     public static class TemplateHTML
        {
            public static string GetTemplate(string pathtoTemplate)
            {
                using (WebClient client = new WebClient())
                {
                    var encodingbody = client.DownloadData(CaminhoTemplate);
                    return Encoding.UTF8.GetString(encodingbody);
                }
            }
        }
    
    var body = TemplateHTML.GetTemplate("http://example.com/umbraco/surface/Template/Template")
    
Please Sign in or register to post replies

Write your reply to:

Draft