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

Posted by Community Admin on 04-Aug-2018 07:22

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

All Replies

Posted by Community Admin on 23-May-2011 00:00

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.

Posted by Community Admin on 23-May-2011 00:00

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

Posted by Community Admin on 23-May-2011 00:00

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

Posted by Community Admin on 23-May-2011 00:00

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

Posted by Community Admin on 24-May-2011 00:00

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.

Posted by Community Admin on 24-May-2011 00:00

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

Posted by Community Admin on 31-May-2011 00:00

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

Posted by Community Admin on 31-May-2011 00:00

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

Posted by Community Admin on 31-May-2011 00:00

How can I delete the fields from the database? By hand, or through code?

Regards,
Daniel

Posted by Community Admin on 31-May-2011 00:00

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

Posted by Community Admin on 31-May-2011 00:00

Okay, clear. Thanks.

This thread is closed