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

EnsureTemplateFolderExists() public method

Creates a directory and copies the needed web.config for razor files if the directory does not exist.
public EnsureTemplateFolderExists ( string templateLocation ) : void
templateLocation string
return void
        public void EnsureTemplateFolderExists(string templateLocation)
        {
            var portalPath = templateLocation == Settings.TemplateLocations.HostFileSystem
                ? HostingEnvironment.MapPath(Settings.PortalHostDirectory)
                : App.OwnerPortalSettings.HomeDirectoryMapPath;
            var sexyFolderPath = Path.Combine(portalPath, Settings.TemplateFolder);

            var sexyFolder = new DirectoryInfo(sexyFolderPath);

            // Create 2sxc folder if it does not exists
            if (!sexyFolder.Exists)
                sexyFolder.Create();

            // Create web.config (copy from DesktopModules folder)
            if (!sexyFolder.GetFiles("web.config").Any())
                File.Copy(HostingEnvironment.MapPath(Settings.WebConfigTemplatePath), Path.Combine(sexyFolder.FullName, Settings.WebConfigFileName));

            // Create a Content folder (or App Folder)
            if (!String.IsNullOrEmpty(App.Folder))
            {
                var contentFolder = new DirectoryInfo(Path.Combine(sexyFolder.FullName, App.Folder));
                if (!contentFolder.Exists)
                    contentFolder.Create();
            }
        }

Usage Example

コード例 #1
0
ファイル: DnnStuffToRefactor.cs プロジェクト: 2sic/2sxc
 // todo: try to cache the result of settings-stored in a static variable, this full check
 // todo: shouldn't have to happen every time
 /// <summary>
 /// Returns true if the Portal HomeDirectory Contains the 2sxc Folder and this folder contains the web.config and a Content folder
 /// </summary>
 public void EnsurePortalIsConfigured(SxcInstance sxc, HttpServerUtility server, string controlPath)
 {
     var sexyFolder = new DirectoryInfo(server.MapPath(Path.Combine(sxc.AppPortalSettings.HomeDirectory, Settings.TemplateFolder)));
     var contentFolder = new DirectoryInfo(Path.Combine(sexyFolder.FullName, Constants.ContentAppName));
     var webConfigTemplate = new FileInfo(Path.Combine(sexyFolder.FullName, Settings.WebConfigFileName));
     if (!(sexyFolder.Exists && webConfigTemplate.Exists && contentFolder.Exists))
     {
         // configure it
         var tm = new TemplateManager(sxc.App);
         tm.EnsureTemplateFolderExists(Settings.TemplateLocations.PortalFileSystem);
     };
 }
All Usage Examples Of ToSic.SexyContent.Internal.TemplateManager::EnsureTemplateFolderExists