Canvas.Helpers.CanvasHelper.GetTemplates C# (CSharp) Method

GetTemplates() public static method

public static GetTemplates ( string type ) : List
type string
return List
        public static List<CanvasTemplate> GetTemplates(string type)
        {
            List<CanvasTemplate> templates = new List<CanvasTemplate>();

            if (!Directory.Exists(HttpContext.Current.Server.MapPath("/Views/Canvas/Templates")))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/Views/Canvas/Templates"));
            }

            if (!Directory.Exists(HttpContext.Current.Server.MapPath("/Views/Canvas/Templates/" + type)))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/Views/Canvas/Templates/" + type));
            }

            DirectoryInfo templateFolder = new DirectoryInfo(HttpContext.Current.Server.MapPath("/Views/Canvas/Templates/" + type));

            FileInfo[] templateViews = templateFolder.GetFiles();

            foreach (FileInfo template in templateViews)
            {

                var index = template.FullName.LastIndexOf("\\Views");

                var m = new CanvasTemplate();

                m.name = template.Name.Replace(".cshtml", "");
                m.path = template.FullName.Substring(index, template.FullName.Length - index);

                templates.Add(m);
            }

            return templates;
        }