Table of Contents

Class CodeFileController

Namespace
Umbraco.Cms.Web.BackOffice.Controllers
Assembly
Umbraco.Web.BackOffice.dll
[Authorize(Policy = "SectionAccessSettings")]
public class CodeFileController : BackOfficeNotificationsController
Inheritance
CodeFileController
Inherited Members

Constructors

CodeFileController(IHostingEnvironment, FileSystems, IFileService, IBackOfficeSecurityAccessor, ILocalizedTextService, IUmbracoMapper, IShortStringHelper, IOptionsSnapshot<GlobalSettings>)

[Obsolete("Use ctor will all params. Scheduled for removal in V12.")]
public CodeFileController(IHostingEnvironment hostingEnvironment, FileSystems fileSystems, IFileService fileService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, ILocalizedTextService localizedTextService, IUmbracoMapper umbracoMapper, IShortStringHelper shortStringHelper, IOptionsSnapshot<GlobalSettings> globalSettings)

Parameters

hostingEnvironment IHostingEnvironment
fileSystems FileSystems
fileService IFileService
backOfficeSecurityAccessor IBackOfficeSecurityAccessor
localizedTextService ILocalizedTextService
umbracoMapper IUmbracoMapper
shortStringHelper IShortStringHelper
globalSettings IOptionsSnapshot<GlobalSettings>

CodeFileController(IHostingEnvironment, FileSystems, IFileService, IBackOfficeSecurityAccessor, ILocalizedTextService, IUmbracoMapper, IShortStringHelper, IOptionsSnapshot<GlobalSettings>, PartialViewSnippetCollection, PartialViewMacroSnippetCollection)

[ActivatorUtilitiesConstructor]
public CodeFileController(IHostingEnvironment hostingEnvironment, FileSystems fileSystems, IFileService fileService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, ILocalizedTextService localizedTextService, IUmbracoMapper umbracoMapper, IShortStringHelper shortStringHelper, IOptionsSnapshot<GlobalSettings> globalSettings, PartialViewSnippetCollection partialViewSnippetCollection, PartialViewMacroSnippetCollection partialViewMacroSnippetCollection)

Parameters

hostingEnvironment IHostingEnvironment
fileSystems FileSystems
fileService IFileService
backOfficeSecurityAccessor IBackOfficeSecurityAccessor
localizedTextService ILocalizedTextService
umbracoMapper IUmbracoMapper
shortStringHelper IShortStringHelper
globalSettings IOptionsSnapshot<GlobalSettings>
partialViewSnippetCollection PartialViewSnippetCollection
partialViewMacroSnippetCollection PartialViewMacroSnippetCollection

Methods

Delete(string, string)

Used to delete a specific file from disk via the FileService

[HttpDelete]
[HttpPost]
public IActionResult Delete(string type, string virtualPath)

Parameters

type string

This is a string but will be 'scripts' 'partialViews', 'partialViewMacros' or 'stylesheets'

virtualPath string

The filename or URL encoded path of the file to delete

Returns

IActionResult

Will return a simple 200 if file deletion succeeds

GetByPath(string, string)

Used to get a specific file from disk via the FileService

public ActionResult<CodeFileDisplay?> GetByPath(string type, string virtualPath)

Parameters

type string

This is a string but will be 'scripts' 'partialViews', 'partialViewMacros' or 'stylesheets'

virtualPath string

The filename or URL encoded path of the file to open

Returns

ActionResult<CodeFileDisplay>

The file and its contents from the virtualPath

GetScaffold(string, string, string?)

Used to scaffold the json object for the editors for 'scripts', 'partialViews', 'partialViewMacros' and 'stylesheets'

public ActionResult<CodeFileDisplay?> GetScaffold(string type, string id, string? snippetName = null)

Parameters

type string

This is a string but will be 'scripts' 'partialViews', 'partialViewMacros' or 'stylesheets'

id string
snippetName string

Returns

ActionResult<CodeFileDisplay>

GetSnippets(string)

Used to get a list of available templates/snippets to base a new Partial View or Partial View Macro from

public ActionResult<IEnumerable<SnippetDisplay>> GetSnippets(string type)

Parameters

type string

This is a string but will be 'partialViews', 'partialViewMacros'

Returns

ActionResult<IEnumerable<SnippetDisplay>>

Returns a list of Umbraco.Cms.Core.Models.ContentEditing.SnippetDisplay if a correct type is sent

PostCreate(string, CodeFileDisplay)

Used to create a brand new file

public ActionResult<CodeFileDisplay> PostCreate(string type, CodeFileDisplay display)

Parameters

type string

This is a string but will be 'scripts' 'partialViews', 'partialViewMacros'

display CodeFileDisplay

Returns

ActionResult<CodeFileDisplay>

Will return a simple 200 if file creation succeeds

PostCreateContainer(string, string, string)

Used to create a container/folder in 'partialViews', 'partialViewMacros', 'scripts' or 'stylesheets'

[HttpPost]
public ActionResult<CodeFileDisplay> PostCreateContainer(string type, string parentId, string name)

Parameters

type string

'partialViews', 'partialViewMacros' or 'scripts'

parentId string

The virtual path of the parent.

name string

The name of the container/folder

Returns

ActionResult<CodeFileDisplay>

PostExtractStylesheetRules(StylesheetData)

Extracts "umbraco style rules" from a style sheet

public StylesheetRule[]? PostExtractStylesheetRules(CodeFileController.StylesheetData data)

Parameters

data CodeFileController.StylesheetData

The style sheet data

Returns

StylesheetRule[]

The style rules

PostInterpolateStylesheetRules(StylesheetData)

Creates a style sheet from CSS and style rules

public string? PostInterpolateStylesheetRules(CodeFileController.StylesheetData data)

Parameters

data CodeFileController.StylesheetData

The style sheet data

Returns

string

The style sheet combined from the CSS and the rules

Remarks

Any "umbraco style rules" in the CSS will be removed and replaced with the rules passed in data

PostSave(CodeFileDisplay)

Used to create or update a 'partialview', 'partialviewmacro', 'script' or 'stylesheets' file

public ActionResult<CodeFileDisplay> PostSave(CodeFileDisplay display)

Parameters

display CodeFileDisplay

Returns

ActionResult<CodeFileDisplay>

The updated CodeFileDisplay model