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

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.

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


Returns

A newly created library file.

Parameters

NameDescriptionType
label This will be used as the file name and as the default class name that is created within the file. Special characters and white spaces are removed and replaced with an underscore in both places. The extension is optional but must be ".cs" if specified. System.String
libraryFolder The Library folder that the class file will be saved into CrownPeak.CMSAPI.Asset

Code Example

C#

Sample:
Asset myNewLibraryFile;
//load the site root properties as it pertains to the current asset
SiteRootProperties srp = Asset.GetSiteRootProperties(asset.Id);    
if(srp!= null && srp.ProjectId > 0)
{
  //if the site root has a project load the library folder in the project
  Asset libraryFolder = Asset.Load(Asset.Load(srp.ProjectId).AssetPath + "/Library");
  myNewLibraryFile = Asset.CreateLibraryFile("MyLibraryfile", libraryFolder);        
}

Connect with Crownpeak