Class FileService
Represents the File Service, which provides access to operations involving IFile objects like Scripts, Stylesheets, Templates, and Partial Views.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
Syntax
public class FileService : RepositoryService, IFileService, IService
Remarks
Many methods in this service are marked as obsolete. For new implementations, use the specific services: IStylesheetService, IScriptService, ITemplateService, IPartialViewService, and their corresponding folder services.
Constructors
View SourceFileService(ICoreScopeProvider, ILoggerFactory, IEventMessagesFactory, IStylesheetRepository, IScriptRepository, IPartialViewRepository, IAuditRepository, IHostingEnvironment, ITemplateService, ITemplateRepository, IUserIdKeyResolver, IShortStringHelper, IOptions<GlobalSettings>)
Initializes a new instance of the FileService class.
Declaration
[Obsolete("Use the non-obsolete constructor instead. Scheduled for removal in Umbraco 19.")]
public FileService(ICoreScopeProvider uowProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, IPartialViewRepository partialViewRepository, IAuditRepository auditRepository, IHostingEnvironment hostingEnvironment, ITemplateService templateService, ITemplateRepository templateRepository, IUserIdKeyResolver userIdKeyResolver, IShortStringHelper shortStringHelper, IOptions<GlobalSettings> globalSettings)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScopeProvider | uowProvider | The core scope provider for database operations. |
| ILoggerFactory | loggerFactory | The logger factory for creating loggers. |
| IEventMessagesFactory | eventMessagesFactory | The factory for creating event messages. |
| IStylesheetRepository | stylesheetRepository | The repository for stylesheet operations. |
| IScriptRepository | scriptRepository | The repository for script operations. |
| IPartialViewRepository | partialViewRepository | The repository for partial view operations. |
| IAuditRepository | auditRepository | The audit repository (no longer used). |
| IHostingEnvironment | hostingEnvironment | The hosting environment for path resolution. |
| ITemplateService | templateService | The template service for template operations. |
| ITemplateRepository | templateRepository | The template repository for direct template access. |
| IUserIdKeyResolver | userIdKeyResolver | The resolver for converting user IDs to keys. |
| IShortStringHelper | shortStringHelper | The short string helper (no longer used). |
| IOptions<GlobalSettings> | globalSettings | The global settings options (no longer used). |
FileService(ICoreScopeProvider, ILoggerFactory, IEventMessagesFactory, IStylesheetRepository, IScriptRepository, IPartialViewRepository, IAuditService, IHostingEnvironment, ITemplateService, ITemplateRepository, IUserIdKeyResolver)
Initializes a new instance of the FileService class.
Declaration
public FileService(ICoreScopeProvider uowProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, IPartialViewRepository partialViewRepository, IAuditService auditService, IHostingEnvironment hostingEnvironment, ITemplateService templateService, ITemplateRepository templateRepository, IUserIdKeyResolver userIdKeyResolver)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScopeProvider | uowProvider | The core scope provider for database operations. |
| ILoggerFactory | loggerFactory | The logger factory for creating loggers. |
| IEventMessagesFactory | eventMessagesFactory | The factory for creating event messages. |
| IStylesheetRepository | stylesheetRepository | The repository for stylesheet operations. |
| IScriptRepository | scriptRepository | The repository for script operations. |
| IPartialViewRepository | partialViewRepository | The repository for partial view operations. |
| IAuditService | auditService | The audit service for logging operations. |
| IHostingEnvironment | hostingEnvironment | The hosting environment for path resolution. |
| ITemplateService | templateService | The template service for template operations. |
| ITemplateRepository | templateRepository | The template repository for direct template access. |
| IUserIdKeyResolver | userIdKeyResolver | The resolver for converting user IDs to keys. |
FileService(ICoreScopeProvider, ILoggerFactory, IEventMessagesFactory, IStylesheetRepository, IScriptRepository, IPartialViewRepository, IAuditService, IAuditRepository, IHostingEnvironment, ITemplateService, ITemplateRepository, IUserIdKeyResolver, IShortStringHelper, IOptions<GlobalSettings>)
Initializes a new instance of the FileService class.
Declaration
[Obsolete("Use the non-obsolete constructor instead. Scheduled for removal in Umbraco 19.")]
public FileService(ICoreScopeProvider uowProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, IPartialViewRepository partialViewRepository, IAuditService auditService, IAuditRepository auditRepository, IHostingEnvironment hostingEnvironment, ITemplateService templateService, ITemplateRepository templateRepository, IUserIdKeyResolver userIdKeyResolver, IShortStringHelper shortStringHelper, IOptions<GlobalSettings> globalSettings)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScopeProvider | uowProvider | The core scope provider for database operations. |
| ILoggerFactory | loggerFactory | The logger factory for creating loggers. |
| IEventMessagesFactory | eventMessagesFactory | The factory for creating event messages. |
| IStylesheetRepository | stylesheetRepository | The repository for stylesheet operations. |
| IScriptRepository | scriptRepository | The repository for script operations. |
| IPartialViewRepository | partialViewRepository | The repository for partial view operations. |
| IAuditService | auditService | The audit service for logging operations. |
| IAuditRepository | auditRepository | The audit repository (no longer used). |
| IHostingEnvironment | hostingEnvironment | The hosting environment for path resolution. |
| ITemplateService | templateService | The template service for template operations. |
| ITemplateRepository | templateRepository | The template repository for direct template access. |
| IUserIdKeyResolver | userIdKeyResolver | The resolver for converting user IDs to keys. |
| IShortStringHelper | shortStringHelper | The short string helper (no longer used). |
| IOptions<GlobalSettings> | globalSettings | The global settings options (no longer used). |
Methods
View SourceCreatePartialView(IPartialView, string?, int?)
Creates a new IPartialView.
Declaration
[Obsolete("Please use IPartialViewService for partial view operations. Scheduled for removal in Umbraco 18.")]
public Attempt<IPartialView?> CreatePartialView(IPartialView partialView, string? snippetName = null, int? userId = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| IPartialView | partialView | The IPartialView to create. |
| string | snippetName | Optional name of a snippet to use as template content. |
| int? | userId | Optional id of the user creating the partial view. |
Returns
| Type | Description |
|---|---|
| Attempt<IPartialView> | An Attempt<TResult> indicating success or failure with the created partial view. |
CreatePartialViewFolder(string)
Creates a folder for partial views.
Declaration
[Obsolete("Please use IPartialViewFolderService for partial view folder operations. Scheduled for removal in Umbraco 18.")]
public void CreatePartialViewFolder(string folderPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | The path of the folder to create. |
CreateScriptFolder(string)
Creates a folder for scripts
Declaration
[Obsolete("Please use IScriptFolderService for script folder operations. Scheduled for removal in Umbraco 18.")]
public void CreateScriptFolder(string folderPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath |
CreateStyleSheetFolder(string)
Creates a folder for style sheets
Declaration
[Obsolete("Please use IStylesheetService for stylesheet operations. Scheduled for removal in Umbraco 18.")]
public void CreateStyleSheetFolder(string folderPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath |
CreateTemplateForContentType(string, string?, int)
Creates a template for a content type
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public Attempt<OperationResult<OperationResultType, ITemplate>?> CreateTemplateForContentType(string contentTypeAlias, string? contentTypeName, int userId = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contentTypeAlias | |
| string | contentTypeName | |
| int | userId |
Returns
| Type | Description |
|---|---|
| Attempt<OperationResult<OperationResultType, ITemplate>> | The template created |
CreateTemplateWithIdentity(string?, string?, string?, ITemplate?, int)
Create a new template, setting the content if a view exists in the filesystem
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public ITemplate CreateTemplateWithIdentity(string? name, string? alias, string? content, ITemplate? masterTemplate = null, int userId = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| string | alias | |
| string | content | |
| ITemplate | masterTemplate | |
| int | userId |
Returns
| Type | Description |
|---|---|
| ITemplate |
DeletePartialView(string, int?)
Deletes a partial view by its path.
Declaration
[Obsolete("Please use IPartialViewService for partial view operations. Scheduled for removal in Umbraco 18.")]
public bool DeletePartialView(string path, int? userId = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path of the partial view to delete. |
| int? | userId | Optional id of the user deleting the partial view. |
Returns
| Type | Description |
|---|---|
| bool | True if the partial view was deleted; otherwise, false. |
DeletePartialViewFolder(string)
Deletes a folder for partial views.
Declaration
[Obsolete("Please use IPartialViewFolderService for partial view folder operations. Scheduled for removal in Umbraco 18.")]
public void DeletePartialViewFolder(string folderPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | The path of the folder to delete. |
DeleteScript(string, int?)
Deletes a script by its name
Declaration
[Obsolete("Please use IScriptService for script operations. Scheduled for removal in Umbraco 18.")]
public void DeleteScript(string path, int? userId = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Name incl. extension of the Script to delete |
| int? | userId | Optional id of the user deleting the script |
DeleteScriptFolder(string)
Deletes a folder for scripts
Declaration
[Obsolete("Please use IScriptFolderService for script folder operations. Scheduled for removal in Umbraco 18.")]
public void DeleteScriptFolder(string folderPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath |
DeleteStyleSheetFolder(string)
Deletes a folder for style sheets
Declaration
[Obsolete("Please use IStylesheetFolderService for stylesheet folder operations. Scheduled for removal in Umbraco 18.")]
public void DeleteStyleSheetFolder(string folderPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath |
DeleteStylesheet(string, int?)
Deletes a stylesheet by its name
Declaration
[Obsolete("Please use IStylesheetService for stylesheet operations. Scheduled for removal in Umbraco 18.")]
public void DeleteStylesheet(string path, int? userId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Name incl. extension of the Stylesheet to delete |
| int? | userId | Optional id of the user deleting the stylesheet |
DeleteTemplate(string, int)
Deletes a template by its alias
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public void DeleteTemplate(string alias, int userId = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| string | alias | Alias of the ITemplate to delete |
| int | userId |
GetPartialView(string)
Gets a IPartialView object by its path.
Declaration
[Obsolete("Please use IPartialViewService for partial view operations. Scheduled for removal in Umbraco 18.")]
public IPartialView? GetPartialView(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path of the partial view. |
Returns
| Type | Description |
|---|---|
| IPartialView | The IPartialView object matching the path, or null. |
GetPartialViewFileContentStream(string)
Gets the content of a partial view as a stream.
Declaration
[Obsolete("Please use IPartialViewService for partial view operations. Scheduled for removal in Umbraco 18.")]
public Stream GetPartialViewFileContentStream(string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the partial view. |
Returns
| Type | Description |
|---|---|
| Stream | The content of the partial view. |
GetPartialViewFileSize(string)
Gets the size of a partial view.
Declaration
[Obsolete("Please use IPartialViewService for partial view operations. Scheduled for removal in Umbraco 18.")]
public long GetPartialViewFileSize(string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the partial view. |
Returns
| Type | Description |
|---|---|
| long | The size of the partial view. |
GetPartialViews(params string[])
Gets a list of all IPartialView objects
Declaration
[Obsolete("Please use IPartialViewService for partial view operations. Scheduled for removal in Umbraco 18.")]
public IEnumerable<IPartialView> GetPartialViews(params string[] names)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | names |
Returns
| Type | Description |
|---|---|
| IEnumerable<IPartialView> | An enumerable list of IPartialView objects |
GetScript(string?)
Gets a IScript object by its name
Declaration
[Obsolete("Please use IScriptService for script operations. Scheduled for removal in Umbraco 18.")]
public IScript? GetScript(string? name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the script incl. extension |
Returns
| Type | Description |
|---|---|
| IScript | A IScript object |
GetScriptFileContentStream(string)
Gets the content of a script file as a stream.
Declaration
[Obsolete("Please use IScriptService for script operations. Scheduled for removal in Umbraco 18.")]
public Stream GetScriptFileContentStream(string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the script. |
Returns
| Type | Description |
|---|---|
| Stream | The content of the script file. |
GetScriptFileSize(string)
Gets the size of a script file.
Declaration
[Obsolete("Please use IScriptService for script operations. Scheduled for removal in Umbraco 18.")]
public long GetScriptFileSize(string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the script file. |
Returns
| Type | Description |
|---|---|
| long | The size of the script file. |
GetScripts(params string[])
Gets a list of all IScript objects
Declaration
[Obsolete("Please use IScriptService for script operations. Scheduled for removal in Umbraco 18.")]
public IEnumerable<IScript> GetScripts(params string[] names)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | names |
Returns
| Type | Description |
|---|---|
| IEnumerable<IScript> | An enumerable list of IScript objects |
GetStylesheet(string?)
Gets a IStylesheet object by its name
Declaration
[Obsolete("Please use IStylesheetService for stylesheet operations. Scheduled for removal in Umbraco 18.")]
public IStylesheet? GetStylesheet(string? path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | Path of the stylesheet incl. extension |
Returns
| Type | Description |
|---|---|
| IStylesheet | A IStylesheet object |
GetStylesheetFileContentStream(string)
Gets the content of a stylesheet as a stream.
Declaration
[Obsolete("Please use IStylesheetService for stylesheet operations. Scheduled for removal in Umbraco 18.")]
public Stream GetStylesheetFileContentStream(string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the stylesheet. |
Returns
| Type | Description |
|---|---|
| Stream | The content of the stylesheet. |
GetStylesheetFileSize(string)
Gets the size of a stylesheet.
Declaration
[Obsolete("Please use IStylesheetService for stylesheet operations. Scheduled for removal in Umbraco 18.")]
public long GetStylesheetFileSize(string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the stylesheet. |
Returns
| Type | Description |
|---|---|
| long | The size of the stylesheet. |
GetStylesheets(params string[])
Gets a list of all IStylesheet objects
Declaration
[Obsolete("Please use IStylesheetService for stylesheet operations. Scheduled for removal in Umbraco 18.")]
public IEnumerable<IStylesheet> GetStylesheets(params string[] paths)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | paths |
Returns
| Type | Description |
|---|---|
| IEnumerable<IStylesheet> | An enumerable list of IStylesheet objects |
GetTemplate(Guid)
Gets a ITemplate object by its guid identifier.
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public ITemplate? GetTemplate(Guid id)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | id | The guid identifier of the template. |
Returns
| Type | Description |
|---|---|
| ITemplate | The ITemplate object matching the identifier, or null. |
GetTemplate(int)
Gets a ITemplate object by its identifier.
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public ITemplate? GetTemplate(int id)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id | The identifier of the template. |
Returns
| Type | Description |
|---|---|
| ITemplate | The ITemplate object matching the identifier, or null. |
GetTemplate(string?)
Gets a ITemplate object by its alias.
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public ITemplate? GetTemplate(string? alias)
Parameters
| Type | Name | Description |
|---|---|---|
| string | alias | The alias of the template. |
Returns
| Type | Description |
|---|---|
| ITemplate | The ITemplate object matching the alias, or null. |
GetTemplateDescendants(int)
Gets the template descendants
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public IEnumerable<ITemplate> GetTemplateDescendants(int masterTemplateId)
Parameters
| Type | Name | Description |
|---|---|---|
| int | masterTemplateId |
Returns
| Type | Description |
|---|---|
| IEnumerable<ITemplate> |
GetTemplateFileContentStream(string)
Gets the content of a template as a stream.
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public Stream GetTemplateFileContentStream(string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the template. |
Returns
| Type | Description |
|---|---|
| Stream | The content of the template. |
GetTemplateFileSize(string)
Gets the size of a template.
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public long GetTemplateFileSize(string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the template. |
Returns
| Type | Description |
|---|---|
| long | The size of the template. |
GetTemplates(int)
Gets a list of all ITemplate objects
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public IEnumerable<ITemplate> GetTemplates(int masterTemplateId)
Parameters
| Type | Name | Description |
|---|---|---|
| int | masterTemplateId |
Returns
| Type | Description |
|---|---|
| IEnumerable<ITemplate> | An enumerable list of ITemplate objects |
GetTemplates(params string[])
Gets a list of all ITemplate objects
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public IEnumerable<ITemplate> GetTemplates(params string[] aliases)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | aliases |
Returns
| Type | Description |
|---|---|
| IEnumerable<ITemplate> | An enumerable list of ITemplate objects |
SavePartialView(IPartialView, int?)
Saves a IPartialView.
Declaration
[Obsolete("Please use IPartialViewService for partial view operations. Scheduled for removal in Umbraco 18.")]
public Attempt<IPartialView?> SavePartialView(IPartialView partialView, int? userId = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IPartialView | partialView | The IPartialView to save. |
| int? | userId | Optional id of the user saving the partial view. |
Returns
| Type | Description |
|---|---|
| Attempt<IPartialView> | An Attempt<TResult> indicating success or failure with the saved partial view. |
SaveScript(IScript?, int?)
Saves a Script
Declaration
[Obsolete("Please use IScriptService for script operations. Scheduled for removal in Umbraco 18.")]
public void SaveScript(IScript? script, int? userId)
Parameters
| Type | Name | Description |
|---|---|---|
| IScript | script | IScript to save |
| int? | userId | Optional id of the user saving the script |
SaveStylesheet(IStylesheet?, int?)
Saves a IStylesheet
Declaration
[Obsolete("Please use IStylesheetService for stylesheet operations. Scheduled for removal in Umbraco 18.")]
public void SaveStylesheet(IStylesheet? stylesheet, int? userId = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IStylesheet | stylesheet | IStylesheet to save |
| int? | userId | Optional id of the user saving the stylesheet |
SaveTemplate(IEnumerable<ITemplate>, int)
Saves a collection of Template objects
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public void SaveTemplate(IEnumerable<ITemplate> templates, int userId = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<ITemplate> | templates | List of Template to save |
| int | userId | Optional id of the user |
SaveTemplate(ITemplate, int)
Saves a Template
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public void SaveTemplate(ITemplate template, int userId = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| ITemplate | template | Template to save |
| int | userId |
SetPartialViewFileContent(string, Stream)
Sets the content of a partial view.
Declaration
[Obsolete("Please use IPartialViewService for partial view operations. Scheduled for removal in Umbraco 18.")]
public void SetPartialViewFileContent(string filepath, Stream content)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the partial view. |
| Stream | content | The content of the partial view. |
SetScriptFileContent(string, Stream)
Sets the content of a script file.
Declaration
[Obsolete("Please use IScriptService for script operations. Scheduled for removal in Umbraco 18.")]
public void SetScriptFileContent(string filepath, Stream content)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the script. |
| Stream | content | The content of the script file. |
SetStylesheetFileContent(string, Stream)
Sets the content of a stylesheet.
Declaration
[Obsolete("Please use IStylesheetService for stylesheet operations. Scheduled for removal in Umbraco 18.")]
public void SetStylesheetFileContent(string filepath, Stream content)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the stylesheet. |
| Stream | content | The content of the stylesheet. |
SetTemplateFileContent(string, Stream)
Sets the content of a template.
Declaration
[Obsolete("Please use ITemplateService for template operations. Scheduled for removal in Umbraco 18.")]
public void SetTemplateFileContent(string filepath, Stream content)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filepath | The filesystem path to the template. |
| Stream | content | The content of the template. |