How to remove Custom Field I had created on Blog Post By Code
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.
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);
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
Hello John,
Currently this is not supported. Custom fields are created per type - BlogPost.
All the best,
Ivan Dimitrov
the Telerik team
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.
Hi John,
Just create a new instance of MetadataManager
. ( var manager = MetadataManager
.GetManager())
Greetings,
Ivan Dimitrov
the Telerik team
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
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
How can I delete the fields from the database? By hand, or through code?
Regards,
Daniel
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
Okay, clear. Thanks.