Sitefinity ASP.NET CMS - Content Management System

KB Article

Home >  Support >  Knowledge Base >  KB Article
How to associate content items with files - ID#1053
Rating: Not rated
Last Modified: 7/16/2008
Related categories: Controls;

Article information

Article relates to

 Sitefinity 3.2 or later

Created by

 Pepi & Rebecca


This article describes how to add a Library selector similar to the Thumbnail selector in News to all modules based on Generic Content:

Library Selector control

The attached LibrarySelector user control gives you the ability to choose and associate files from the Images and Documents module, as well as from the file system.

The LibrarySelector control has a DisplayMode property that gets or sets the selected library mode. By default the property is set to Auto and the control works in as if in Image mode, i.e. the Insert an image dialog opens.
In the example below DisplayMode is set to Document, which means that the Insert a document dialog will open when the user clicks Select. The user has the option to upload a file to a document library or the file system and to select files already uploaded in document libraries or physical folders.

This control can be used both in Sitefinity administration (as it implements the ITextControl interface) and in the public part.

I. To enable it in the News module administration, follow these steps:

   1. In the ~/UserControls folder, create a subfolder called Libraries and place the two files from the attached archive: LibrarySelector.ascx and LibrarySelector.ascx.cs.

   2. Open the application web.config and in section <metaFields>, add this key:

<add key="News.Document" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="">  
   
 

   3. Register the control in the ControlPanelEdit.ascx and ControlPanelInsert.ascx templates located in ~/Sitefinity/Admin/ControlTemplates/News folder:

<%@ Register TagPrefix="uc" Src="~/UserControls/Libraries/LibrarySelector.ascx" TagName="LibrarySelector" %> 
 
 

   4. Declare the control inside the ItemTemplate of the ContentMetaFields control and set its ID to the meta key:

<li> 
   <asp:Label ID="Label9" AssociatedControlID="Document" runat="server"><asp:Literal ID="Literal24" runat="server" Text="Document"></asp:Literal> <em id="Em2" runat="server"></em></asp:Label> 
   <uc:LibrarySelector ID="Document" runat="server" DisplayMode="Document"></uc:LibrarySelector> 
</li> 



II.
To display the LibrarySelector in the Add Controls toolbox and use it as a public control, you need to add the following declaration in the <toolboxControls> section of the application web.config:

<add name="Library Selector" section="Misc" url="~/UserControls/Libraries/LibrarySelector.ascx" /> 
 


Article Files

  • LibrarySelector.zip



  • Article Comments

    There are no comments yet.
    Please Sign In to rate this article or to add it to your favorites.