More in this section

Forums / Developing with Sitefinity / Generic Content saving at runtime strips p tag

Generic Content saving at runtime strips p tag

5 posts, 0 answered
  1. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    04 Mar 2010
    Link to this post
    I don't think this is a bug; I think I'm just missing a setting somewhere. I'm attempting to create a generic content event item at runtime based on user input using the EventsManager. however when I populate the Content property, and save the item, the p tags that surround the content are stripped.

    the content item has only one paragraph of text, which is that one p tag. the text is saved, but not inside the p tag.

    in the rad editor this would happen because I had the StripPTags property set... but how do I configure this to work with the EventsManager so that the full content is kept as it is sumbitted?

    thanks!
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Mar 2010
    Link to this post
    Hello SelArom,

    Thank you for using our services. 

    Could you please show us a snippet of your code how you create the event items. I have tried this with the bellow code and p tags were not being stripped:
    var eventsManager = new EventsManager("Events");
    IContent newEvent = eventsManager.Content.CreateContent("text/html");
    newEvent.Content = "<p>this is some sample content<p>";
    newEvent.SetMetaData("Title", "New Event Item");
    newEvent.SetMetaData("Event_Start", DateTime.Now);
    newEvent.SetMetaData("Event_End", DateTime.MaxValue);
    eventsManager.Content.SaveContent(newEvent, ContentStatus.Published);
    //get newly created event
    IEvent eventItem = eventsManager.GetEvents()[0] as IEvent;

    You can take a look at attached image for reference.

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    05 Mar 2010
    Link to this post
    this looks exactly like mine EXCEPT I'm saving with status of DRAFT not PUBLISH

    would that make a difference?
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Mar 2010
    Link to this post
    Hi SelArom,

    Thank you for getting back to me.

    I have modified the code to create draft items just to double check there was nothing wrong, as method called is the same there should not be differences in the content. The result is in the attached image. The code uses is can be found bellow:
    var eventsManager = new EventsManager("Events");
    IContent newEvent = eventsManager.Content.CreateContent("text/html");
    newEvent.Content = "<p>this is some sample content<p>";
    newEvent.SetMetaData("Title", "Test Draft Item");
    newEvent.SetMetaData("Event_Start", DateTime.Now);
    newEvent.SetMetaData("Event_End", DateTime.MaxValue);
    eventsManager.Content.SaveContent(newEvent, ContentStatus.Draft);
    //get newly created event
    IEvent eventItem = eventsManager.GetEvents(DateTime.MinValue,DateTime.MaxValue,"",ContentStatus.Draft)[0] as IEvent;

    Is it possible that you preview the text of the newly created draft item in the Sitefinity UI, and then when you click edit the editor strips the p tag from the loaded html content? 

    Regards,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    05 Mar 2010
    Link to this post
    you were exactly right. I don't know why, I could swear I had fixed the ContentFilters property to remove the stripptags, but when I looked at it the property wasn't even there. strange,

    but I restored it and made sure to leave off that filter and now all is well

    sorry about that!
Register for webinar
5 posts, 0 answered