1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Adding Metadata to Generic Content Items

Adding Metadata to Generic Content Items

4 posts, 1 answered
  1. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    02 Sep 2009
    Link to this post
    Hello,

    A client has requested that we add a "Public Access" checkbox field to each Library item so that library items may be filtered by this field in a custom control I have developed to view documents. I have previously added a checkbox to user profiles, so I thought this would be similar, however I've encountered some problems.

    This is what I have done so far:

    I added the following metaField in web.config
    <cmsEngine defaultProvider="Generic_Content"
      ... 
      <metaFields> 
        ... 
        <add key="Libraries.PublicAccess" valueType="Boolean" visible="True" searchable="false" sortable="false" defaultValue="True"/> 
        ... 
      </metaFields> 
      ... 
    </cmsEngine> 

    I then setup the external template for /Sitefinity/Admin/ControlTemplates/Libraries/LibraryItemEdit.ascx
    I added a checkbox like so...
    <li> 
      <asp:Label ID="lblPublicAccess" AssociatedControlID="PublicAccess" runat="server" Text="Public Access"></asp:Label> 
      <asp:CheckBox ID="PublicAccess" runat="server /> 
    </li> 

    Now, when I edit a library item, I get the checkbox, and it defaults to whatever value I set in web.config.
    So far so good!

    But now the problems begin...
    When I clicked save, the value wouldn't save. This is confirmed by querying the database. The new record shows up in sf_GCMetaData, but there is never a value. (I also tried this whole setup with a ShortString and Text box, and it had the same results) Also, every time I open it back up, it reverts to the default value, so something fishy's going on here.

    I tried adding the following code to the OnClick event of the save buttons, and it runs, all the data is right, but I get the same result of no data being stored.
    CheckBox cbPublicAccess = itemMetaFields.GetControl("PublicAccess"falseas CheckBox; 
    LibraryManager lm = new LibraryManager(); 
    Guid id = new Guid(Request.QueryString["Param"]); 
    IContent item = lm.GetContent(id); 
             
    item.SetMetaData("PublicAccess", cbPublicAccess.Text.ToString()); 
    Even if I immediately call item.GetMetaData("PublicAccess") after setting it, I get the right data.

    What am I doing wrong?

    Thank you for your support,

    David
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    03 Sep 2009
    Link to this post
    Hello David,

    Could you confirm whether you have added your newly created key to the metakeys attribute of LibraryInfo node? If not please add your key there as show below for the default metakeys..

        <libraries defaultGenericProvider="Libraries"
                <genericContentProviders> 
                    <add providerName="Libraries" publicationDateField="Publication_Date"/> 
                </genericContentProviders> 
                <libraryInfo> 
                    <add name="Image" title="Image Library" defaultExtenstions=".png, .jpg, .jpeg, .gif" metaKeys="Author, AlternateText, Extension, Name, Height, Width, Size, Category"></add> 
                    <add name="Document" title="Document Library" defaultExtenstions=".doc, .docx, .rtf, .txt, .pdf, .ppt, .pps, .pptx, .html, .xls, .xlsx" metaKeys="Author, Description, Extension, Name, Size, Category"></add> 
                    <add name="Custom" title="Custom Library" defaultExtenstions=".*" metaKeys="Author, Description, Extension, Name, Size, Category"></add> 
                    <add name="Video" title="Video" defaultExtenstions=".wmv" metaKeys="Author, Extension, Name, Size, Category, Description, Guid1"></add> 
                    <!-- Viddler can co-exists with other libraries--> 
                    <!--<add name="Viddler" title="Viddler Library" defaultExtenstions=".avi, .mpg, .mov, .wmv, .wma, .3gp" metaKeys="Author, Description, Extension, Name, Size, Category"></add>--> 
                </libraryInfo> 
                <!-- before using extensionMapping be you uncomment LibraryHttpModule in handlers and httpHandlers sections --> 
                <extensionMapping defaultExtension=".sflb.ashx"
                    <!--<add key=".jpg"/> 
                    <add key=".pdf"/> 
                    <add key=".csv"/> 
                    <add key=".xls"/>--> 
                </extensionMapping> 
            </libraries> 


    Also the CheckBox value is of BooleanType. In the database there should be 1 - true or 0 - false. As I can see it you are setting metadata value as your texbox text - this valueType is not boolean. It is text.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    03 Sep 2009
    Link to this post
    Thank you for your support.

    I had not previously added the new key to the metakeys attribute of LibraryInfo node. After doing so, it now works.
    The issue with text/boolean was simply a typo on my part while sending you sample code. I had it correct in my control.

    Thank you very much!

    David

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    03 Sep 2009
    Link to this post
    Hello David,

    Glad to hear that this has helped.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 1 answered