Loading...
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Introduction

This document describes the legacy Asset system and its specific features including: customizing assets, displaying assets, securing assets and authorization and storing data. EPiServer Commerce allows you to associate assets with products and SKUs. Those associated assets are then available in the Entry.Assets collection. However, assets can also be independently rendered and retrieved. EPiServer Commerce also includes controls that allow you to display or make digital assets downloadable.

Out-of-the-box, EPiServer Commerce comes with asset management providers for file storage, MSSQL storage and Amazon S3. You can also create your own asset management provider. Refer to Storing Data for more information.

Classes referred to here 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 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. Can be retrieved using EntityManager. This is a Manager class which allows you to retrieve 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

This is an example of how to create 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, allowing you to retrieve blob information. In most cases, you will not need to use this provider. If there is complex business logic you want to implement regarding the storage provider or you want to override business logic in the provider, BlobStorageProvider can be useful.

BlobStorage is a Manager class to retrieve BlobStorageProviders. It also exposes events that can be listened to, for instance when an asset is added, allow 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.
Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 21, 2014

Recommended reading