How could I save template file (cshtml) to database instead of file.
Hi all,
I have published the Umbraco on Azure app services, maybe we need more than one services for that, so I want save the template file to database or blob that I can make it in sync. how should I do?
Thanks for your help. I have read the documentation, but I still don’t know how to implement it. I haven’t seen a more complete description for the FILE service, where should I define it, and where should I use it?
Register an event in IComponent , this event will trigger once template saved from the backend.
Please find the below samples
Sync all the templates to DB on an API call.
[RoutePrefix("syncapi")]
public class SyncApiController:UmbracoApiController
{
private IFileService _fileService;
public SyncApiController(IFileService fileService){
_fileService = fileService;
}
[HttpGet]
[Route("template")]
public HttpStatusCode Template()
{
var all templates=_fileService.GetTemplates();//get all templates
var homeTemplate = _fileService.GetTemplate("home"); //get template with -- alias "home"
var content=homeTemplate.content; // get content/code in home template
return HttpStatusCode.OK;
}}
How could I save template file (cshtml) to database instead of file.
Hi all,
I have published the Umbraco on Azure app services, maybe we need more than one services for that, so I want save the template file to database or blob that I can make it in sync. how should I do?
regards cary
Hi Cary,
You can use File service ,here https://our.umbraco.com/documentation/reference/management/services/FileService/
Regards DK 🙂
Hi DK,
Thanks for your help. I have read the documentation, but I still don’t know how to implement it. I haven’t seen a more complete description for the FILE service, where should I define it, and where should I use it?
thanks
cary
Hi Cary,
you can achieve this by two way's.
Please find the below samples
Sync all the templates to DB on an API call.
Api Call - http://localhost:1234/syncapi/template
Create a class file by inheriting IComponent & Register
Subscribing an Event
Regards DK :)
Hi DK,
Thanks for your excellent answer, I will take a try, thanks again.
Best Regards
Cary
is working on a reply...