Documentation > CMS Template API Library > Asset

CrownPeak.CMSAPI.Asset

Encapsulates the CMS Asset. Methods for loading and manipulating assets and their data are found in here. Meta data about the asset such as the Label and Id are represented by properties. (asset.Label, asset.Id) Custom data that has been provided from the client is accessible through an indexer (see Item(String) Property below)

NameDescriptionType
AddDependencyTo

Adds a dependency on this asset to the provided asset. So when this asset publishes, it will check the asset or its children and see if they need to be published.

Method
ClearSchedule

Clears the schedule date set for the specified asset. The schedule name must match with a schedule name in the workflow for the asset.

Method
ClearUpload

Clears the specified upload's meta data from the asset. If there is an array of uploads with this name, they are all removed unless a specific element is named.

Method
CopyAsset

Copies the given asset to the given destination using the provided label. The copied asset is returned. Use Asset.IsLoaded on the returned asset to see if the copy was successful. The context.Error string will give you the reason for failure. NOTE: If the original asset had a model, it is not set on the copy.

Method
CreateBranch

Use this to create a branch from another asset.

Method
CreateCSharpDeveloperTemplate

Create a developer template file with the given label in the given location. These are templates that run on their own like assets. They are commonly used for CSS or JS files.

Method
CreateFile

This function creates a new asset in the cms with the specified label, template and optional workflow in the specified saveLocation.

Method
CreateFolder

Creates a folder in the given location using the given FolderType

Method
CreateFromBase64

Create a binary (uploaded asset) from a base64 string.

Method
CreateFromHex

Create a binary (uploaded asset) from a Hex string.

Method
CreateFromUploadedFile

Create a binary (uploaded asset) from an UploadedFile object.

Method
CreateLibrary

Create a library with the given label in the given location.

Method
CreateLibraryFile

Creates a new Class File within the specified Library. This function will return an asset even if it fails to create one. Upon failure it will return an empty asset and you will need to check the IsLoaded property to see if it was successfully created or Not.

Method
CreateLibraryReference

Create a reference in library with the given label in the given location.

Method
CreateNewAsset

Creates an asset in the given folder using a given model.

Method
CreateNewSiteRoot

Create a Site root with the given label in the given location.

Method
CreateProject

Create a Project with the given label in the given location.

Method
CreateTemplate

Create a template with the given label in the given location. It can be created in template folder.

Method
CreateTemplateFile

Create a template file with the given label in the given location. It can be created in a template only.

Method
CreateTemplateFolder

Create a template folder with the given label in the given location. It must be created in another template folder.

Method
CreateThumbnail

Creates a thumbnail of the specified size from the currently loaded image. A ThumbnailKey is required. The resulting image will be stored on the asset unless we are in upload.aspx, in that case it will be saved to the asset or current panel at the time the input form is saved. To change the currently uploaded image in place use the uploadContext.UploadedFile.UploadKey as the thumbnail Key. Important note, if calling from upload.aspx and the thumbnail key is not the same as the upload, make sure that the thumbnail key is in the list of strings passed as the hiddenFields parameter of the Input.ShowAcquireImage() call. Note: Due to memory limitations, the pixel count of the source image cannot be more than 10 million.

Method
CreateThumbnail

Creates a thumbnail of the specified size from the currently loaded image. A ThumbnailKey is required. The resulting image will be stored on the asset unless we are in upload.aspx, in that case it will be saved to the asset or current panel at the time the input form is saved. To change the currently uploaded image in place use the uploadContext.UploadedFile.UploadKey as the thumbnail Key. Important note, if calling from upload.aspx and the thumbnail key is not the same as the upload, make sure that the thumbnail key is in the list of strings passed as the hiddenFields parameter of the Input.ShowAcquireImage() call. Note: Due to memory limitations, the pixel count of the source image cannot be more than 10 million.

Method
CropImage

Crop the current image using the box defined by x, y, xx, yy and scaling to width and height. Saving on the asset using thumbnailKey as a fieldname.

Method
CropImage

Crop the current image stored in the UploadedFile using the box defined by x, y, xx, yy and scaling to width and height. Saving on the asset using thumbnailKey as a fieldname.

Method
Delete

Deletes the current asset instance. It is marked for deletion and purged from the database after 2 weeks. The current user must have permission to delete the asset. The root asset (id == 0), may not be deleted.

Method
DeleteContentField

Deletes a content field with the given key.

Method
DeleteContentFields

Delete all the content fields whose names are in the given list.

Method
DeleteMetaField

Deletes a meta data field with the given key.

Method
DeleteMetaFields

Delete all the meta data fields whose names are in the given list.

Method
ExecuteWorkflowCommand

Execute the specified workflow command on the given asset. The workflow command must be available from the current state of the given asset. ACL for executing workflow commands are respected. Workflow filters for that particular workflow command are respected.

Method
ExecuteWorkflowCommand

Execute the specified workflow command on the given list of assets. The workflow command must be available from the current state of each asset in the list. If one asset fails, the method continues on the rest of the list. ACL for executing workflow commands are respected. Workflow filters for that particular workflow command are respected.

Method
GetContent

Gets the content fields and caches them in this asset's indexer, then returns them in a Dictionary.

Method
GetContentFields

Gets a dictionary of fields dependending on the fieldNames argument. This function is called on the current asset for all templates before running to load all DB fields. Will look for both fields equaling the name and equaling "upload#" plus the name unless the specified name already starts with upload#. If you don't provide this param, or pass null, or pass an empty list or pass a list that contains a * element, then all fields in the db are returned. Found fields are added to this asset instance's cache so there will be no more DB hits when you access them. If the optional to load all fields is taken, then any other fields lookups on the asset instance will not go back to the DB.

Method
GetDateOverlap

Gets a List of Assets from the CMS that contain a date range which overlaps the specified range.

Method
GetFileList

Gets a list of files in this folder.

Method
GetFileList

Gets a list of files in this folder. All parameters are Optional.

Method
GetFilterList

Get a List of Assets from the CMS, based on a custom filter, searching recursively from this folder asset.

NOTE: If using GetFilterList in a scenario that has multiple levels of nested folders within the returned list of assets, please consider setting the "useAssetsPathFilter" configuration flag to TRUE. When enabled, this API will use the folder table in place of the generated temp table we now use for folders in filter lists.

Method
GetFolderList

Gets a list of subfolders in this folder.

Method
GetFolderList

Gets a list of subfolders in this folder. All parameters are optional.

Method
GetFolderType

Gets type of folder such as Project or Site Root. If the asset is not loaded or not a folder it will return "unspecified".

Method
GetLink

Renders a link to the asset based upon the current context. Upon publishing, it will return the link to the published page. Upon previewing, it will return the cms preview link to the page.

Method
GetMeta

Returns the meta data in a Dictionary.

Method
GetPanels

Get panels based on list name from data already saved into the asset. Note: The usual case is that the data for the panel comes from a List Panel on an input form. Once the form has been saved, this function will always return at least one entry, even if no data was entered on the panel. Therefore, you may want to check the data in the PanelEntry before using it, depending on the use case.

Method
GetPanelsFromFolder

Used for navigation lists. Panels are initialized using children of the first argument "folder" asset instance, which must be a folder. Data from the panels is stored on "this" asset. This could be used, to store the order of the list or to associate other metadata such as enabled, disabled. If there is more than one child from the same branch, the asset with the highest asset id is returned. Assets are bound to the panels by branch id unless the optional idName parameter is specified The optional idName and labelName parameters are for backward-compatibility with navigation panels stored with the old API. If an idName is specified, then the assets are bound to the panels by asset id instead of the branch id. It is not necessary to add hidden fields with the id or branch id to the form, they are automatically generated. If using this method to initialize an input panel, additional code is required on the post_input.aspx template to copy the data from the current asset to the folder (or other asset where you are storing the metadata), unless you are storing the data on the current asset that you are editing.

Method
GetPanelsFromFolder

The same as GetPanelsFromFolder(Asset,String,AssetParams,AssetType,String,String) but with FilterParams instead of AssetParams.

Method
GetPanelsFromFolder

Used for navigation lists. Panels are initialized using children of "this" asset instance or this instances parent, if this is a file. Data from the panels is stored on this asset. This could be used, to store the order of the list or to associate other metadata such as enabled, disabled. If there is more than one child from the same branch, the asset with the highest asset id is returned. Assets are bound to the panels by branch id unless the optional idName parameter is specified This method is overloaded. This version would be the most common case where the metadata is stored on the same folder whose children we are using to initialize the list. If using this method to initialize an input panel, additional code is required on the post_input.aspx template to copy the data from the current asset to the folder. The other version would allow you to save the metadata on a different asset such as the current asset. The optional idName and labelName parameters are for backward-compatibility with navigation panels stored with the old API. If an idName is specified, then the assets are bound to the panels by asset id instead of the branch id. It is not necessary to add hidden fields with the id or branch id to the form, they are automatically generated.

Method
GetProject

For a given asset find the project. If the asset is in a project or a child of a project that project will be returned. If the asset is a child of a site root, we will look for a project that is a child of a site root and that will be returned. If the asset is a child of a site root and does not have a child project, it will look for a sibling project to the site root and return that. If no project is found by either method, we will return an empty asset. If using a site root to find the project and more than one child or sibling is found which is a project, an error will be set and no project will be returned.

Method
GetSiteRoot

For a given asset find the closest parent that is of FolderType.SiteRoot

Method
GetSiteRootProperties

Get the site root configuration properties. User must have permission to view the site root.

Method
GetSystemHistory

Returns a list of system audit entries based on the parameters in the request

Method
GetWorkflowByAsset

Gets information about a workflow from its workflow asset. This is an asset that is a "workflow file" that can be found in "/System/Workflows" or in the "Workflows" subfolder of a project when using project specific workflows. Use Asset.LoadDirect() with the actual asset id to get an instance of this asset.

Method
GetWorkflowByWorkflowId

Gets information about a workflow from its workflow id. This can be found on the general properties page of assets that use this workflow as the "Workflow Id" or in the "Points To Workflow" field of a worfklow asset.

Method
GetWorkflows

Gets a list of workflows given the current asset. For most assets this will be all the workflows which are found under /System/Worklows. If your asset is part of a project or part of a site root that has a project and if that project has its own workflows you will see those workflows.

Method
Load

Loads the asset with the specified path object Use IsLoaded to see if loading was successful. If the asset does not exist in one of the valid states, an appropriate branch may be returned. Results will depend on the current valid statuses (See context.FilterStatus). Depending on the use case there will be a list of legal statuses, the returned asset must not only match the provided path, but it must either have one of the valid statuses or have been published to a server with one of the valid statuses or have one of the statuses configured in its current workflow step. If there is more than one match, the asset with the highest id and therefore the one created most-recently is returned. Valid Statuses: Preview: All the states checked under System, MyAccount, Preferences in the section title "My Default Browse State(s)", plus "" (No-workflow) Publishing: The state associated with the current server for the workflow step and "" (no workflow). View Output: All state(s) associated with all servers configured for the current asset for the current workflow step and "" (no workflow). All Others Contexts: All states are legal

Method
Load

Loads the asset by id or an appropriate branch. For example, if you pass the id of an asset that is "RETIRED", and you are publishing to "LIVE", it will look for an asset on the same branch as the asset you were looking for that is in the "LIVE" state. Use IsLoaded to see if loading was successful. Note: Use LoadDirect to ignore statuses. If the asset does not exist in one of the valid states, an appropriate branch may be returned. Results will depend on the current valid statuses (See context.FilterStatus). Depending on the use case there will be a list of legal statuses, the returned asset must not only match the provided path, but it must either have one of the valid statuses or have been published to a server with one of the valid statuses or have one of the statuses configured in its current workflow step. If there is more than one match, the asset with the highest id and therefore the one created most-recently is returned. Valid Statuses: Preview: All the states checked under System, MyAccount, Preferences in the section title "My Default Browse State(s)", plus "" (No-workflow) Publishing: The state associated with the current server for the workflow step and "" (no workflow). View Output: All state(s) associated with all servers configured for the current asset for the current workflow step and "" (no workflow). All Others Contexts: All states are legal

Method
Load

Loads an asset from the specified path - for example "/Site/Folder/Page". "cpt_internal" style links - "" and strings which contain only an asset id "870" are also supported. Use IsLoaded to see if loading was successful. Id paths which do not have "/cpt_internal" such as "/828/856/870" are not supported, use Asset.LoadByIdPath() instead. Results will depend on the current valid statuses (See context.FilterStatus). Note: Use LoadDirect to ignore statuses. Depending on the use case there will be a list of legal statuses, the returned asset must not only match the provided path, but it must either have one of the valid statuses or have been published to a server with one of the valid statuses or have one of the statuses configured in its current workflow step. If there is more than one match, the asset with the highest id and therefore the one created most-recently is returned. If the asset does not exist in one of the valid states, an appropriate branch may be returned. Results will depend on the current valid statuses (See context.FilterStatus). Depending on the use case there will be a list of legal statuses, the returned asset must not only match the provided path, but it must either have one of the valid statuses or have been published to a server with one of the valid statuses or have one of the statuses configured in its current workflow step. If there is more than one match, the asset with the highest id and therefore the one created most-recently is returned. Valid Statuses: Preview: All the states checked under System, MyAccount, Preferences in the section title "My Default Browse State(s)", plus "" (No-workflow) Publishing: The state associated with the current server for the workflow step and "" (no workflow). View Output: All state(s) associated with all servers configured for the current asset for the current workflow step and "" (no workflow). All Others Contexts: All states are legal

Method
LoadByIdPath

Loads the asset specified by the id path which might look like /828/856/870, use Load(string) for "cpt_internal" style. If the asset does not exist in one of the valid states, an appropriate branch may be returned. Use IsLoaded to see if loading was successful. Results will depend on the current valid statuses (See context.FilterStatus). Depending on the use case there will be a list of legal statuses, the returned asset must not only match the provided path, but it must either have one of the valid statuses or have been published to a server with one of the valid statuses or have one of the statuses configured in its current workflow step. If there is more than one match, the asset with the highest id and therefore the one created most-recently is returned. Valid Statuses: Preview: All the states checked under System, MyAccount, Preferences in the section title "My Default Browse State(s)", plus "" (No-workflow) Publishing: The state associated with the current server for the workflow step and "" (no workflow). View Output: All state(s) associated with all servers configured for the current asset for the current workflow step and "" (no workflow). All Others Contexts: All states are legal

Method
LoadDirect

Load an asset with the given asset path, if it exists, regardless of the state or context. If there are two or more assets with the same path, the asset with the highest id number (most-recently created) is returned. Use IsLoaded to see if loading was successful. Don't use this if you expect the asset to have branches. It will load assets, that may not be available on the server where you are publishing.

Method
LoadDirect

Load an asset with the given asset id, if it exists, regardless of the state or context. Use IsLoaded to see if loading was successful. Don't use this if you expect the asset may be branch. It will load assets, that may not be available on the server where you are publishing.

Method
LoadDirect

Load an asset with the given asset path, if it exists, regardless of the state or context. If there are two or more assets with the same path, the asset with the highest id number (most-recently created) is returned. Use IsLoaded to see if loading was successful. Don't use this if you expect the asset to have branches. It will load assets, that may not be available on the server where you are publishing.

Method
Move

Moves this asset to the specified destination folder.

Method
Publish

Publish the asset. If we are in a session, it will reuse the same session, otherwise a new session is created. Only files are currently supported.

Method
RecompileLibrary

Pass the id of a library folder and it will compile.

Method
Rename

Renames the asset to the specified label.

Method
Route

Route the given asset to a workflow step that corresponds to the given status. The asset must have workflow. The status must correspond to one of the steps on the asset's current workflow. If more than one workflow step has the given state, then the lowest step will be chosen. Use Status.Load(string statusName) to load the status. If it returns false, check the context.Error property. Currently, you may only route file assets, routing folders in not supported.

Method
RouteAssets

Route assets in the given list to a workflow step that corresponds to the given status. The status must correspond to one of the steps on the assets' workflow. If more than one workflow step has the given state, then the lowest step will be chosen. Use Status.Load(string statusName) to load the status. If it returns false, check the context. Error property. Currently, you may only route file assets, routing folders in not supported.

Method
RouteCollection

Route assets in the given list of collection to a workflow step that corresponds to the given status. The status must correspond to one of the steps on the assets' workflow. If more than one workflow step has the given state, then the lowest step will be chosen. Use Status.Load(string statusName) to load the status. If it returns false, check the context.Error property. Currently, you may only route file assets, routing folders in not supported.

Method
SaveAssetAsAttachment

Used to save an uploaded asset's file contents to another asset as an attachment.

Method
SaveBase64AsAttachment

Save a new attachment using base64 data as a source.

Method
SaveContent

Saves either the asset's indexer or the content provided in a dictionary to the database as this asset's fields. If any of the values in the fieldsToStore dictionary are null, they will be stored as an empty string.

Method
SaveContentField

Saves a content field to the database. If the value is null, it will be stored as an empty string.

Method
SaveEmailAttachment

Saves an email attachment to an asset. This function has been designed to run under the SmtpImportContext and will throw a contract error if called from the wrong context. Once the attachment has been saved it is treated like an uploadedFile.

Method
SaveHexAsAttachment

Save a new attachment using a hex string data as a source.

Method
SaveMeta

Saves either the asset's indexer or the meta data fields provided in a dictionary to the database as this asset's meta data fields. If any of the values in the fieldsToStore dictionary are null, they will be stored as an empty string.

Method
SaveMetaField

Saves a meta data field to the database. If the value is null, it will be stored as an empty string.

Method
SaveSource

Updates the source of a template or library file. This will automatically trigger the template or library code to compile if necessary.

Method
SaveUploadedFile

Save an uploaded file to an asset. Usually used in upload.aspx to save the original image before creating a thumbnail. Import Note: This would be called from upload.aspx when using Input.ShowAcquireImage() to upload an image. You need to provide this key to the ShowAcquireImage call in the optional "hiddenFields" parameter, otherwise things may not save correctly. When calling from upload.aspx, saving is not immediate. Data is stored temporarily and is saved when the form is committed.

Method
SetAsSiteRoot

Makes the asset into a site root. Must be a folder and user must have permission to create a site root in the parent folder of the asset.

Method
SetHidden

Sets the hidden flag on the instance.

Method
SetModel

Sets a model on a folder. Pass the id of another folder to use as a model.

Method
SetSchedule

Allows you to set a scheduled workflow transition (usually a publish or retire) for the specified asset. You must provide the schedule name as configured in the workflow. The schedule date must include a date and time. Input time is assumed to be Pacific Time.

Method
SetSchedule

Allows you to set a scheduled workflow transition (usually a publish or retire) for the specified asset. You must provide the schedule name as configured in the workflow. The schedule date must include a date and time and a sourceTimeZone.

Method
SetSchedule

Allows you to set a scheduled workflow transition (usually a publish or retire) for the specified asset. You must provide the schedule name as configured in the workflow. The schedule date must include a date and time and a sourceTimeZone.

Method
SetSiteRootProperties

Can be used to set the site root properties. User must have both view permission on the actual site root and permission to create and edit site roots set. You cannot edit branch configuration at this time.

Method
SetTemplate

Set a template on an asset. The id must be the id of a folder that contains plugin files such as output.asp or input.aspx, etc.

Method
SetWorkflow

Change the current asset to the workflow specified by the workflowId parameter.

Method
SetWorkflow

Change the current asset to the workflow specified by the workflowName parameter.

Method
SetWorkflowByAsset

Change the current asset to the workflow specified by the workflowAsset parameter.

Method
Show

Similar to "include" but instead evaluates another asset preview/output within its own context as opposed to the current asset context. This is often used to combine different templates to create a composite template.

Method

Update a binary (uploaded asset) from a base64 string.

Method
AssetPath

Gets the assets full path.

Property
BranchId

Gets the branch id. This is initialized if the asset has been branched. It applies to assets with workflow only. If there is no branch, the asset id is returned.

Property
CheckoutDate

The date and time the asset was checked out. Might not be initialized, use HasValue to check.

Property
CheckoutUserId

The user id of the user who has the asset checked out. Use User.Load to get the User object for this id.

Property
ChildId

Gets the child id. If this is a shortcut, the child id will be the id of the asset to which this one points, otherwise, it is the same as the id.

Property
CreateDate

The date and time the asset was created.

Property
CreatedFromModelId

This is the id of the model asset used to create this one. Will be -1 if no model was used. (Formerly base model Id)

Property
CreateUserId

The user id of the user who created the asset. Use User.Load to get the User object for this id.

Property
ExtractedContent

Used with Search G2. If this is a binary asset and content parsing is enabled, this is extracted on upload and stored as a JSON string. In the SearchG2Context contexts, this will be populated on-the-fly, if not loaded yet. Failure will return empty object. Check context.Error for details on failure.

Property
ExtractedContentRawJson

The Raw Json string used to populate the object returned by ExtractedContent. This is search G2 related. Data is populated at upload time. If data is not available, the data is uploaded to ACB and parsed on-the-fly if it is running in a Search G2 template.

Property
FolderId

Gets the asset id of the parent folder.

Property
Id

Gets the asset's unique id.

Property
IsBinary

This is an uploaded binary asset, not a rendered page.

Property
IsFile

Whether this asset is of AssetType.File

Property
IsFolder

Whether this asset is of AssetType.Folder

Property
IsHidden

Is the asset hidden. Usually archived assets are hidden. This can be set through workflow or using the UI.

Property
IsLoaded

Is the asset loaded. Call this after a load to see if the load was successful. If false, GetLink() will return an empty string

Property
Item[String]

Gets or sets the with the specified key. Setting a value is not permanent unless SaveContent is called with no arguments. Data is set in memory. Assigning a value using [] on the implicit "asset" which is always available can be used to pass data from new.aspx to input.aspx and from post_input.aspx to post_save.aspx. If assigning a value of null, it will be stored as an empty string

Property
Label

Gets the label or name of this asset. Call asset.Rename to change the asset label.

Property
Meta

The contents of metadata. The content of the metadata field is accessed with []"

Property
ModelId

Gets or sets the model id. This is initialized if the asset has a model. For folders. This is the id of a folder whose children show up in the "New" menu when this folder is selected. If there is no model, -1 is returned.

Property
ModifiedDate

A change in the asset's content properties Might not be initialized, use HasValue to check.

Property
ModifiedUserId

The user id of the user who last modified the asset. Use User.Load to get the User object for this id.

Property
Parent

Gets this asset's parent folder. Tip: Don't use this if all you need is the parent's Id. Use FolderId.

Property
PublishDate

The asset's last publish date Might not be initialized, use HasValue to check.

Property
PublishUserId

The user id of the user who last published the asset. Use User.Load to get the User object for this id.

Property
Raw

The raw contents of asset fields. This removes any automatically-inserted markup from a content field. The content of the field is accessed with []"

Property
Size

The size of the asset. If it is a file, it is the size of the file in bytes. If it is a folder it is the number of children in that folder.

Property
StatusDate

The last time the asset's status was changed. Might not be initialized, use HasValue to check.

Property
StatusUserId

The user id of the user who last changed the asset's status. If the asset is not checked out, 0 is returned. Use User.Load to get the User object for this id.

Property
TemplateId

Gets the template id. This is the id of the folder holding ASP or C# template files that run at various times for this asset.

Property
TemplateLabel

The Asset's Template folder label. . Will be blank, if the asset has no template.

Property
Type

Gets the type. It will be either a File or a Folder. It can be either an AssetType.File or an AssetType.Folder.

Property
UploadedFiles

Uploaded Files that are saved on this asset. Use this collection to read uploaded file data. You can change the value of the UploadFile.Path parameter, but you need to pass it back to asset.SaveUploadedFile() to save it.

Property
WorkflowStatus

Gets the Status object representing this asset's workflow.

Property

Connect with Crownpeak