Copying Files and Folders

Copy files and folders to a C1 CMS Website with the file package fragment installer

The FilePackageFragmentInstaller can copy files and directories to a C1 CMS System. Apart form raw copying, this fragment installer can also load assemblies into the installer's application domain.

The example below shows two files and two directories being copied. Note that the elements within the </mi:Add> element all exist in the null namespace.

 
<mi:Add 
	installerType="Composite.Core.PackageSystem.PackageFragmentInstallers.FilePackageFragmentInstaller, Composite"
	uninstallerType="Composite.Core.PackageSystem.PackageFragmentInstallers.FilePackageFragmentUninstaller, Composite">

	<Files>
	<!-- allowOverwrite: overwrite an existing target file-->
	<!-- assemblyLoad: load the copied file from a temp dir. Ex: if the file contains a data type -->
		<File sourceFilename="~\PageTemplates\FancyTemplate.cshtml" 
			targetFilename="~\App_Data\PageTemplates\FancyTemplate.cshtml" 
			allowOverwrite="false"/>
		<File sourceFilename="~\Bin\CustomDataTypes.dll" 
			targetFilename="~\Bin\CustomDataTypes.dll" 
			assemblyLoad="true" 
			allowOverwrite="false"
			onlyAdd="true"/>
		</Files>

	<Directories>
	<!-- allowOverwrite: allow overwrite of existing target files -->
	<!-- deleteTargetDirectory: delete the target directory before the copy 
                              is issued -->
		<Directory sourceDirectory="~\PageTemplates\" 
             targetDirectory="~\App_Data\PageTemplates\" 
             allowOverwrite="true" 
             deleteTargetDirectory="false"/>
		<Directory sourceDirectory="~\Views\" 
             targetDirectory="~\Views\" 
             allowOverwrite="true" 
             deleteTargetDirectory="true"/>
	</Directories>
</mi:Add>

The <Files /> element

The Files element can contain none, one, or more File elements, which allow you to copy individual files. You can also specify that the installer system should load an individual assembly into the application domain, making types (like IData types) it defines available to the system.

The File element has the following attributes:

  • sourceFilename: A tilde-based path that points to a file in the package's ZIP file.
  • targetFilename: A tilde-based path that points to a file location on the C1 CMS file structure.
  • allowOverwrite: When “false”, the system will halt installation if the file already exists.
  • onlyAdd: When "true", the system will skip copying the file if the file already exists.
  • assemblyLoad: Optional. When “true”, the system will load the file into the application domain. This is useable when later install steps reference IData types contained in a DLL.

Note. allowOverwrite="true" and onlyAdd="true" (both "true") are not allowed on the same file. At least one of these attributes must be "false".

The <Directories /> element

The Directories element can contain none, one, or more Directory elements, which allow you to copy whole directory structures.

  • sourceDirectory: A tilde-based path that points to a directory in the package's ZIP file.
  • targetDirectory: A tilde-based path that points to a directory location on the C1 CMS file structure.
  • allowOverwrite: When “false”, the system will halt installation if the file already exists.
  • deleteTargetDirectory: When “true”, the destination directory will first be deleted if it exists.