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

Forums / Developing with Sitefinity / GetMetaData and firing in one Item content Metafield

GetMetaData and firing in one Item content Metafield

6 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    06 May 2009
    Link to this post
    Hi,

    I triing to get if my value stored in Metafield as string guid is here, but this method only fire the exposed items like ID or Title. Could you suggest one sol to get the stored metafields to later Update the contents.

    IList ListAllItems = manager.Content.GetContent();  
    foreach (IContent cont in ListAllItems)  
    {  
    if (cont.GetMetaData("RefId") == "730ffdc2-dc3a-4a69-bb98-0018d2948180")//No Firing  
    {//some action}  

    Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    06 May 2009
    Link to this post
    Hi Pierre,

    I am not able to reproduce the problem you have. Check out the sample below:

        EventsManager eventsManager = new EventsManager("Events"); 
            IList listofEvets = eventsManager.Content.GetContent(); 
            string result = "content is not in the list"
            foreach (IContent contentItem in listofEvets) 
            { 
                // here using custom metakey 
                if (contentItem.GetMetaData("ID").ToString().Equals("22-22")) 
                { 
                    result = "content is in the list"
                    break
                } 
            } 
            Response.Write(result); 


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    06 May 2009
    Link to this post
    Hi Ivan,

    Thanks, but my Guid is not guid cms is Shortext Metafields in one content.ID  linking external table. I need some expression like GetContentByMeta or filter expression. Regards.

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 May 2009
    Link to this post
    Hello Pierre,

    If you are using external table to store the data( that is not part of Sitefinity) you should use web services to use the api. EventsManager does not  have parameter that knows from which database to get the items. It only works with a provider name that you can specify in the web.config.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    08 May 2009
    Link to this post

    Hi Ivan,

    Could you explain more about use webservices and linking external databases using the api. I have made implementations using external tables and i would see other methods.

    No others ways to get metafileds other than filtering?

    regards

  6. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    09 May 2009
    Link to this post
    Hello Pierre,

    I am not very sure I understand what you are trying to do.
    This is what I understood:
    • You are customizing a Generic-Content based module
    • You have a custom metafield RefId
    • You want to perform some action on all content items that has this custom meta field

    Meta fields are of type object. By default, the comparison operator (== in C#) for object compares references (same as System.Object.ReferenceEquals). You, however, have defined your metafield to be a string (
    Shortext). Therefore, you must call the Equals method, which is overridden in string.

    Try with the following code:

    IList allContentItems = manager.Content.GetContent();   
    foreach (IContent content in allContentItems)   
       object refIdField = content.GetMetaData("RefId"); 
       if (refIdField == null
       { 
          continue
       } 
     
       Guid refId = Guid.Empty; 
       try 
       { 
          refId = new Guid(refIdField.ToString()); 
       } 
       catch (FormatException) 
       { 
          continue
       } 
     
       // your logic goes here 
    }  

    By the way, there is a meta field type "Guid", which you should use if that is what you need.

    All the best,
    Dido
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
6 posts, 0 answered