This topic lists possible ways for extending the Images and Documents module programmatically. This could be done by
changing the web.config file, or making use of methods provided by the Library Manager. Also, there are helper classes that provide additional
functionality when managing Images and Documents.
Changes to the web.config File
The web.config file could be used to extend the functionality of Images and Documents. The module could allow more extensions or could perform a different URL
rewriting than specified by default.
| web.config |
Copy Code |
|
<cmsEngine defaultProvider="Generic_Content">
<providers>
<clear/>
<add name="Libraries" urlRewriteFormat="[ProviderName]/[LibraryName]/[Name].aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" visible="False" defaultMetaField="Name" applicationName="/Libraries"
allowVersioning="True" allowLocalization="False" localizationProviderName=""
allowWorkflow="False" securityProviderName="" versioningProviderName="" connectionStringName="GenericContentConnection" type="Telerik.Libraries.Data.DefaultProvider, Telerik.Libraries.Data"/>
</providers>
...
|
URL Rewriting
The URL rewrite format could be extended by changing the metadata - LibraryName, Name - in the following default setting:
|
Copy Code |
|
urlRewriteFormat="~/{Provider}/{LibraryName}/[Name].sflb"
|
The possible metadata values are listed in the <metaFields> tag in <cmsEngine>. They are: Name, Width,
Height, Size, Extension, AlternateText, Author, Category.
 |
Do not remove or change {ProviderName}. If this meta field is removed, the default provider will
be used. However, the default provider is the Generic Content one, and it does not provide the necessary functionality for the Images and Documents
module. |
Setting Library Extensions
The <libraryInfo> section includes the allowed extensions for each type of library. They could be set to different values here. Also, meta
fields are set per library type, and not in general for the whole module.
| web.config |
Copy Code |
|
<libraries defaultGenericProvider="Libraries">
...
<libraryInfo>
<add name="Image" title="Image Library"
defaultExtenstions=".png, .jpg, .gif" metaKeys="Author, AlternateText, Extension, Name, Height, Width, Size,
Category"></add>
<add name="Document" title="Document Library"
defaultExtenstions=".pdf, .doc" metaKeys="Author, Extension, Name, Size, Category"></add>
<add name="Custom" title="Custom Library"
defaultExtenstions=".png, .jpg, .gif" metaKeys="Extension, Name, Size, Category"></add>
</libraryInfo>
</libraries>
|
Adding Custom Meta Field to File Properties
To add an additional field to the properties of an image or a document, the following code should be added to the web.config file:
 |
In the following code, change all instances of Name_of_Field with the specific name of the meta field to
be created. |
- Add a key to the <metaFields> section:
| <metaFields> |
Copy Code |
|
<add key="Libraries.Name_of_Field" valueType="ShortText"
visible="True" searchable="True" sortable="True" defaultValue="" />
|
- Add a key to the <libraryInfo> section:
| <libraryInfo> |
Copy Code |
|
<add name="Custom" title="Custom Library" defaultExtenstions=".*" metaKeys="Author, Description, Extension, Name, Size, Category, Name_of_Field">
</add>
|
- There is an additional step that should be taken - the control panel template should be changed to display the new field. Add a label, a textbox, and a literal to the
template:
| Control Panel Template |
Copy Code |
|
<sfGCn:ContentMetaFields ID="editMetaFields" runat="server">
...
<li>
<asp:Label ID="Label8" runat="server"
AssociatedControlID="Name_of_Field" Text="Name_of_Field"></asp:Label>
<asp:TextBox runat="server" ID="Name_of_Field"
MaxLength="255" TextMode=MultiLine></asp:TextBox>
<p class="example">
<asp:Literal ID="Literal10" runat="server"
Text="Text that defines the field" />
</p>
</li>
|
The path to the control panel template for image libraries is ~/Sitefinity/Admin/ControlTemplates/Libraries/ControlPanelEdit_Image.ascx , while the
one for document or custom libraries is ~/Sitefinity/Admin/ControlTemplates/Libraries/ControlPanelEdit.ascx.
Query Strings
If a download query string is added to the link of a file in a library, and is set to true, the file will be directly accessed for
download. If false (as is by default), the file will be opened for viewing instead.
Example:
http://www.my_domain.com/MyFile.sflb?download=true
There are four query strings that are available only for image files:
-
width, height -> the strings provide measures and the image is stretched to fit in them. Example:
http://www.my_domain.com/MyFile.sflb?width=100&height=100
-
decreaseOnly -> when true, the image could only be decreased to fit in the measures set by the width and height strings.
Still, if the image is smaller, it would not be enlarged. Example:
http://www.my_domain.com/MyFile.sflb?decreaseOnly=true&width=100&height=100
-
proportional -> when true (by default), the image is stretched only proportionally until it fits in the measures set by
the width and height strings. Example:
http://www.my_domain.com/MyFile.sflb?proportional=true&width=100&height=100
See Also