Documentation > CMS Template API Library > Asset > CopyAsset(String,Asset,Asset)

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.

public CrownPeak.CMSAPI.Asset CopyAsset(String,Asset,Asset)


Returns

The newly created asset.

Parameters

NameDescriptionType
label The name to use for the copied asset. System.String
saveLocation The folder where you will save the copy. CrownPeak.CMSAPI.Asset
assetToCopy The asset to copy. CrownPeak.CMSAPI.Asset

Code Example

C#

Sample:
Asset folderAsset = Asset.Load("/Site/myFolder");
            
Asset assetToCopy = Asset.Load("/Site/myFolder/myfile");
//Copy the asset.
Asset newAsset = Asset.CopyAsset("newname", folderAsset, assetToCopy);
if (!newAsset.IsLoaded) Out.WriteLine("Copy Failed: " + context.Error);

Connect with Crownpeak