More in this section

Forums / Bugs & Issues / How to remove Custom Field I had created on Blog Post By Code

How to remove Custom Field I had created on Blog Post By Code

11 posts, 0 answered
  1. John
    John avatar
    17 posts
    Registered:
    03 Mar 2008
    23 May 2011
    Link to this post
    Hallo,

    Is there anyway i can remove Custom Fields from Blog Post by code ? Can anyone give me a sample code ?
    I am using Sitefinity 4.1.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 May 2011
    Link to this post
    Hello John,

    Here is a sample code that shows how to remove custom fileds

    public void RemoveCustomFields(IList<string> fields)
            {
                foreach (var field in fields)
                {
                    var fieldName = field;
                    var metaField = this.MetaType.Fields.SingleOrDefault(f => f.FieldName == fieldName);
                    if (metaField != null)
                    {
                        this.MetadataManager.Delete(metaField);
                    }
                }
            }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. John
    John avatar
    17 posts
    Registered:
    03 Mar 2008
    23 May 2011
    Link to this post
    Thank you.... i will do it tomorrow morning.... i got mssql problem and need to reinstall...

    By the way is there anyway i could created custom fields for each blog ?

    Just assume i have created Blog with name "Publication" which then will contains many post , which each post
    requires custom fields like : thumbnailurs(text),ServiceLines(multichoices) and Industry(multichoices)

    and another blog named as "Property" which will contains many post which each post will requires custom fields:
    AgentName(text), Location(text)

    Because what i have seen was once i modify the Blog Post with additional custom fields...the changes applied to others Blogs as well.

    How to make each Post has unique custom fields (for Publication and Agent name) ?

    many thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 May 2011
    Link to this post
    Hello John,

    Currently this is not supported. Custom fields are created per type - BlogPost.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. John
    John avatar
    17 posts
    Registered:
    03 Mar 2008
    24 May 2011
    Link to this post
    Hi Ivan Dimitrov,

    I tried the code but it produce errors....it is asking a references .....could you give the namespace i need to add to make it run ? so basically i create a asp button on my custom control and put your code inside the onclick function

    are you sure we need "this" statement on the code..it seems it breaks the code when i tried to run it.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 May 2011
    Link to this post
    Hi John,

    Just create a new instance of MetadataManager. ( var manager = MetadataManager.GetManager())

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Daniel Plomp
    Daniel Plomp avatar
    112 posts
    Registered:
    14 Jun 2012
    31 May 2011
    Link to this post
    I want to delete some custom fields of the products module. Should I run this code first and then remove the fields from the Model\ProductItem class?

    Where should I call this function?

    Regards,
    Daniel
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    31 May 2011
    Link to this post
    Hi Daniel ,

    Yes this will delete the filed and you need to remove all references to it that are in your code. Note that the database data won't be deleted.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Daniel Plomp
    Daniel Plomp avatar
    112 posts
    Registered:
    14 Jun 2012
    31 May 2011
    Link to this post
    How can I delete the fields from the database? By hand, or through code?

    Regards,
    Daniel
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    31 May 2011
    Link to this post
    Hello Daniel ,

    There is no API that will delete this data. You should write a script or do it manually.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  11. Daniel Plomp
    Daniel Plomp avatar
    112 posts
    Registered:
    14 Jun 2012
    31 May 2011
    Link to this post
    Okay, clear. Thanks.
11 posts, 0 answered