ToSic.SexyContent.Internal.TemplateManager.GetTemplateFiles C# (CSharp) Method

GetTemplateFiles() public method

Returns all template files in the template folder.
public GetTemplateFiles ( HttpServerUtility server, string templateType, string templateLocation ) : IEnumerable
server System.Web.HttpServerUtility
templateType string
templateLocation string
return IEnumerable
        public IEnumerable<string> GetTemplateFiles(HttpServerUtility server, string templateType, string templateLocation)
        {
            var templatePathRootMapPath = server.MapPath(GetTemplatePathRoot(templateLocation, App));
            var directory = new DirectoryInfo(templatePathRootMapPath);

            EnsureTemplateFolderExists(templateLocation);

            // Filter the files according to type
            var fileFilter = "*.html";
            switch (templateType)
            {
                case RazorC:
                    fileFilter = "*.cshtml";
                    break;
                case RazorVb:
                    fileFilter = "*.vbhtml";
                    break;
                case TokenReplace:
                    fileFilter = "*.html";
                    break;
            }

            var files = directory.GetFiles(fileFilter, SearchOption.AllDirectories);
            return (from d in files where d.Name != Settings.WebConfigFileName select (d.FullName).Replace(templatePathRootMapPath + "\\", "").Replace('\\', '/'));
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Bind the template files from the given template location
        /// </summary>
        /// <param name="TemplateType">The template type</param>
        /// <param name="TemplateLocation">The template location</param>
        /// <param name="TemplateDropDown">The template dropdown to databind</param>
        private void BindTemplateFiles(string TemplateType, string TemplateLocation, DropDownList TemplateDropDown)
        {
            var tm = new Internal.TemplateManager(App);

            TemplateDropDown.DataSource = tm.GetTemplateFiles(Server, TemplateType, TemplateLocation);
            TemplateDropDown.DataBind();
        }