1

I want to retrieve all Meta keys and value for a particular component , I am using web forms and I have duplicate Meta key's in my Custom_meta table. I want to read them on content delivery side. enter image description here

The code I have tried

string templateUri = "tcm:3-4-32";
ComponentPresentationFactory cpf = new ComponentPresentationFactory(3);
ComponentMetaFactory cmf = new ComponentMetaFactory(3);
Criteria criteria = new ItemTypeCriteria(16);
Query query = new Query(criteria);
foreach (string uri in query.ExecuteQuery())
{
    ComponentPresentation cp = cpf.GetComponentPresentation(uri, templateUri);
    // check if component presentation is published to the broker
    if (cp != null)
    {
        IComponentMeta meta = cmf.GetMeta(uri);
        CustomMeta customMeta = meta.CustomMeta;
        foreach (DictionaryEntry de in customMeta.NameValues)
        {
            Response.Write(string.Format("{0}: {1} ({2})<br/>", 
                           de.Key, 
                           ((NameValuePair) de.Value).Value, 
                           ((NameValuePair) de.Value).Name));
        }
    }
}

But it doesn't give me the value for both the articles , I get only 4 entries in my log, so only one article value.(may be because of key is duplicate) , is there any way to read Duplicate Keys from Custom Meta?

0
-1
    string templateUri = "tcm:3-4-32";
    ComponentPresentationFactory cpf = new ComponentPresentationFactory(3);
    ComponentMetaFactory cmf = new ComponentMetaFactory(3);
    Criteria criteria = new ItemTypeCriteria(16);
    Query query = new Query(criteria);
    foreach (string uri in query.ExecuteQuery())
    {
        ComponentPresentation cp = cpf.GetComponentPresentation(uri, templateUri);
        // check if component presentation is published to the broker
        if (cp != null)
        {
            IComponentMeta meta = cmf.GetMeta(uri);
            CustomMeta customMeta = meta.CustomMeta;
             NameValuePair nvp = (NameValuePair)customMeta.NameValues["Articles"];

             int i = 0;
            foreach (var s in nvp.MultipleValues)
            {
                allComponentUris[i] = Convert.ToString(s);
                i++;
            }
        }

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.