Sitefinity CMS

Libraries Helper Classes Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Generic Content Based Modules > Images and Documents > Libraries > Libraries Helper Classes

Glossary Item Box

Using the LibraryManager class requires manipulation with data specific to only one provider. Still, there are some methods that are non-provider-specific. For this purpose, there are two additional classes available for Libraries: LibraryInfo and LibraryHelper that provide additional methods for managing libraries as part of the Images and Documents module.

 

Class LibraryInfo

The LibraryInfo class (Telerik.Libraries assembly) provides information about libraries. The constructor has three overloads - the passed parameter could be a library name, a library object or an element of type LibraryInfoElement. The constructors set the values of the three LibraryInfo properties - name, title, and extensions. They could be used to get the values for these properties for a specified library.

 

Class LibraryInfo Copy Code
public LibraryInfo(string libraryName)
public LibraryInfo(ILibrary library)
public LibraryInfo(LibraryInfoElement element)

 

Here is a sample usage of this class where a class instance is used with the GetAllLibraries(string typeName, bool isEqual) method:

ImageEditorDialog Copy Code
libraries = this.Manager.GetAllLibraries(LibraryInfo.Library_Document_Name, true);

 

 

Class LibraryHelper

The LibraryHelper class (Telerik.Libraries assembly) provides conversions of types and sizes.

  • There are two methods for converting a string of extensions to an array, and the other way round. These methods are ConvertExtensionsToArray and ConvertExtensionsToString.
  • There are methods that convert a value in Bytes to either KiloBytes (KB) or MegaBytes (MB), as well as the other way round. These methods are: GetSizeInMB and GetSizeInKBConvertKBtoBytes and ConvertMBtoBytes.
  • The IsLibraryFull method returns a boolean value of whether the specified library object is no longer able to hold more items. 
  • The FormatSizeString method converts a size value (of type long) to a string.
Class LibraryHelper Copy Code
public static string[] ConvertExtensionsToArray(string extensions)
public static string ConvertExtensionsToString(string[] extensions)
public static string FormatSizeString(long size)
public static double GetSizeInMB(long sizeInBytes)
public static double GetSizeInKB(long sizeInBytes)
public static long ConvertKBtoBytes(double sizeInKB)
public static long ConvertMBtoBytes(double sizeInMB)
public static bool IsLibraryFull(ILibrary library)

 

 

For example, this class could be used when the user is required to work with more user-friendly sizes in the interface such as KB rather than Bytes. At the same time the code requires Bytes. Here is a sample usage of this class in this case where the ConvertKBtoBytes(double sizeInKB) method is used:

LibraryEditor Copy Code
library.MaxFileSize = LibraryHelper.ConvertKBtoBytes(result2);

 

See Also