Icon

How does Sitecore Update Package Work – Creating File/Folder Commands

Posted 10/26/2016 by Subramanian Ramanathan

In our previous blogs we discussed on how to create Item Commands. But what if we will have to create file/folder commands.

We will have to create FileSystemDataItem for creating File Commands, using the appropriate Files of File System.

FileSystemDataItem fileDataItem = new FileSystemDataItem(@"SourceWebsiteRootPath\", @"RelativeFolderPath\", "FileNameWithExtension");

With FileSystemDataItem we can create Add and Delete File Commands,

//This will add the file into target filesystem if it doesn’t exist
AddFileCommand addFileCommand = new AddFileCommand(fileDataItem);

If the File already exists, it will be overwritten.
If the Relative Folder Path doesn’t exist in the target file system, the folder path will be created automatically.

//This will delete the file from target filesystem if exists
DeleteFileCommand deleteFileCommand = new DeleteFileCommand(fileDataItem);

For creating Folder Commands we will have to create FolderDataItem, using the appropriate Folders of File System.

FolderDataItem folderDataItem = new FolderDataItem(@"SourceWebsiteRootPath\", @"RelativeFolderPath\", "FolderName");

With FolderDataItem we can create Add and Delete Folder Commands,

//This will add the folder into target filesystem if it doesn’t exist
AddFolderCommand addFolderCommand = new AddFolderCommand(folderDataItem);

If the Folder already exists, it will not delete the files that are existing under the folder.
If the Relative Folder Path doesn’t exist in the target file system, the folder path will be created automatically.

//This will delete the folder from target filesystem if exists
DeleteFolderCommand deleteFolderCommand = new DeleteFolderCommand(folderDataItem);

Similar to Item Commands, Collision Behavior for File Commands can be Force(default) or Skip.
If Collision Behavior is not set or is set to Force, then the existing items will be overwritten if there is a collision and the Action would be 'Overwrite Existing'. If Collision Behaviour is set to Skip, then the existing items will not be updated if there is a collision and the Action would be 'Keep Existing'.

Share:

Add your comment

 
 

 

Archive

Syndication