Click or drag to resize
FileSystemRepositoryHelperGetFileSystemName Method (String, String, Int32, Int32)
Gets file system safe representation of name. The resulting name does not exceed maxNameLength characters in length. maxNameLength must accommodate hashLength and delimiting character.

Namespace: CMS.ContinuousIntegration
Assembly: CMS.ContinuousIntegration (in CMS.ContinuousIntegration.dll) Version: 12.0.0
Syntax
C#
public static string GetFileSystemName(
	string name,
	string fullName,
	int maxNameLength,
	int hashLength
)

Parameters

name
Type: SystemString
Name to be transformed to file system safe representation.
fullName
Type: SystemString
Full name for given name. The full name is used for the purpose of hash computation. Null means the full name is the same as name.
maxNameLength
Type: SystemInt32
Max length of the resulting name.
hashLength
Type: SystemInt32
Number of hash characters to be included in the resulting name, if hashing is needed.

Return Value

Type: String
Name in file system safe representation.
Exceptions
ExceptionCondition
ArgumentExceptionThrown when name is null or empty or fullName is empty.
ArgumentOutOfRangeExceptionThrown when hashLength is not a positive integer or maxNameLengthis not greater than (hash length + 1) - the extra character is for hash delimiter.
Remarks

The name processing is similar to code name processing. Diacritics in Latin characters is removed, illegal characters are replaced by '_' (underscore), multiple '.' (dot) are grouped to single '.', leading and trailing '.' and '_' are trimmed.

Specify the fullName parameter to avoid file system name collisions when name is some shortcut or human-readable form of fullName.

Examples
The following code creates 2 file system names, which differ in their hash only
string articleFileSystemName1 = FileSystemRepositoryHelper.GetFileSystemName("Article", "/Path/To/Some/Document/Named/Article", 50, 10);
string articleFileSystemName2 = FileSystemRepositoryHelper.GetFileSystemName("Article", "/Path/To/Different/Document/Named/Article", 50, 10);

// Produces result similar to:
//   article@1234567890
//   article@0987654321
The following code shows how to create a human-readable file name from a name, which would otherwise result in hash only (due to special characters processing)
string defaultFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("/", 50, 10);
string customFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", "/", 50, 10);

// Produces result similar to:
//   @1234567890
//   root@1234567890
The following code demonstrates the difference between providing a name and full name pair for obtaining a human-readable name and why the same can not be achieved with name only. Let's assume we have an object representing a root of a tree (named "/") and we want a human-readable file system name to store such object
string customFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", "/", 50, 10);
string wrongCustomFileSystemName = FileSystemRepositoryHelper.GetFileSystemName("root", 50, 10); // This is wrong. If another object named "root" would exist, its name would collide with the custom name for "/"

// Produces result similar to:
//   root@1234567890           The hash value is computed from "/"
//   root
See Also