Hide menu Last updated: Oct 12 2015

Note: Episerver uses the Episerver asset system by default. If you want to enable the legacy asset management system, set the UseLegacyAssetSystem configuration setting to true in the web.config files of both the Commerce Manager and the front-end sites. 

This topic describes the legacy asset management system and its features, including: customizing assets, displaying assets, securing assets and authorization, and storing data. Episerver Commerce lets you associate assets with products and SKUs. Those associated assets are then available in the Entry.Assets collection. However, you can render and retrieve assets independently. Episerver Commerce also includes controls that let you display or make digital assets downloadable.

Episerver Commerce comes with asset management providers for file storage, MSSQL storage and Amazon S3. You can also create your own asset management provider. See Storing Data for information.

Classes in this topic are available in the following namespaces:

Item assets

ItemAsset represents an asset association with a SKU. Provides the linking information (SKU and Asset IDs), and is a simple object with properties. The Entry has a collection of these objects representing the assets associated with an entry.

Example: using Entry object

C#
ItemAsset[] assets = Entry.Assets;
foreach (ItemAsset asset in assets)
{
int assetId = asset.AssetKey;
string groupName = asset.GroupName;
}

Folder elements

FolderElementEntity

Contains the information pertaining to the asset. Also contains a method to get the virtual URL associated with an asset (GetUrl()).

Example: using FolderElementEntity

C#
FolderElementEntity[] asset = EntityManager.List<FolderElementEntity>(FolderElementEntity.ClassName, filters);
        string url = asset0.GetUrl();
        DateTime dateCreated = asset0.Created;

Contains a static method to create a new asset.

Example: creating an asset

C#
FolderElementEntity.Create(asset parent folder id, file name, System.IO.Stream)
Contains static methods to copy, delete, and move assets.

Example: copying, deleting and moving assets

C#
FolderElementEntity.Copy(element object ref, parent folderid);
            FolderElementEntity.Delete(element object ref);
            FolderElementEntity.Move(element object ref, new parent folderid);

This object also provides access to custom fields that you create in the Business Foundation {BF} definition of the FolderElement class.

Example: accessing custom fields

C#
FolderElementEntity[] asset = EntityManager.List<FolderElementEntity>(FolderElementEntity.ClassName, filters);
        string additionalInfo = asset0.Properties"MyAddedProperty".Value.ToString();

FolderEntity

Represents an asset folder, and is useful when you are navigating the asset hierarchy. Retrieve with EntityManager. This is a Manager class that retrieves FolderElementEntity and FolderEntity objects.

Example: retrieving FolderEntity objects

C#
FolderEntity[] folders = EntityManager.List<FolderEntity>(FolderEntity.ClassName, filters);
        string name = folders0.Name;
        PrimaryKeyId folderId = folders0.PrimaryKeyId.Value;

Creating a Folder

The following example creates an asset folder.

Example: creating a folder using CreateFolder

C#
private int CreateFolder(string name) 
            { 
                try
                { 
                                FolderEntity folder = new FolderEntity(); 
                                folder.Name = name; 
                                folder.PrimaryKeyId = BusinessManager.Create(folder); 
                                //Moves folder under the root 
                                FolderEntity.Move(folder, 1); 
                                return folder.PrimaryKeyId.Value; 
                } 
                catch (Exception ex) 
                { 
                                LogManager.GetLogger("Asset Upload").Error(ex.Message, ex); 
                                return -1; 
                } 
            } 

            //Adding an asset 

            Private void AddFilesToFolder(int siteFolderId) 
            { 
                            foreach (FileInfo info in dir.GetFiles()) 
                            { 
            FolderElementEntity entity = FolderElementEntity.Create(siteFolderId, info.FullName, info.OpenRead()); 
                            }

Asset providers

BlobStorageProvider

Represents an asset provider and returns information about the provider, to retrieve blob information. In most cases, you do not need to use this provider. If you want to implement complex business logic regarding the storage provider or override business logic in the provider, use BlobStorageProvider.

BlobStorage is a Manager class to retrieve BlobStorageProviders. It also exposes events that can be listened to, for instance when an asset is added, allowing custom logic to be implemented during asset management activities.

Example: using BlobStorageProvider

C#
BlobStorageProvider prov = BlobStorage.Providerselement.BlobStorageProvider;
        string description = prov.Description;
        string name = prov.Name;

BlobInfo

Simple object with blob information about the asset. Its properties are a subset of the FolderElementEntity object.

Example: using BlobInfo

C#
BlobStorageProvider prov = BlobStorage.Providerselement.BlobStorageProvider;
        BlobInfo info = prov.GetInfo(new Guid(myFolderElementEntity.BlobUid.ToString()));
        string fileName = info.FileName;

There are four primary database tables with asset information:

  • CatalogItemAsset. Contains the asset to product/SKU mapping.
  • cls_FolderElement. Contains information regarding the assets.
  • cls_Folder. Contains information regarding folders in the asset system.
  • McBlobStorage. Contains the asset blob information used by the SqlBlobStorageProvider.

Comments