More in this section

Forums / Developing with Sitefinity / Scheduling News programmatically

Scheduling News programmatically

5 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    13 Nov 2008
    Link to this post
    Hi,

    Could you help to scheduling news programmatically. I try to build one Adv module based on News and one easier planning to manage. Could you suggest some solutions to manage the post.

    Regards
  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    13 Nov 2008
    Link to this post
    Hello Pierre,

    news module does not implement "real" scheduling, but rather the publication and expiration dates which are then used on the public side to filter the news that have been published but not expired.

    In Sitefinity 4.0 we are planning to release a scheduling service with which you will be able to execute arbitrary code in certain intervals or at certain time.

    You could achieve something similar on your own, by scheduling a task on your server that would execute some code.

    I hope you'll find this information helpful. Let us know if there is anything else we can do for you.

    Sincerely yours,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    13 Nov 2008
    Link to this post
    Hi Ivan,

    I have found one library at Codeproject to make similar.

     http://www.codeproject.com/KB/aspnet/WebTask.aspx

    Could you teach me to select one category of News and change the timer Publish and expire. I'm searching to publish the days pairs (2,4,6) and unpublish the days impairs(3,5,7) for a lot of news changing my content programmatically. Thanks.
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    18 Nov 2008
    Link to this post
    Hello Pierre,

    Here is how to get news items with certain category, and perform some updates on the Publication and Expiration dates metafields. The example also shows if the publication date - day is even or odd:
    protected void Page_Load(object sender, EventArgs e) 
        { 
            //Select News from given category 
            ContentManager cm = new ContentManager("News"); 
            IList Items = cm.GetContent(); 
            foreach (IContent item in Items) 
            { 
                //read the metafields 
                string Category = item.GetMetaData("Category").ToString(); 
                DateTime pubDate = (DateTime)item.GetMetaData("Publication_Date"); 
                DateTime expDate = (DateTime)item.GetMetaData("Expiration_Date"); 
                //check if the item is in the corresponding category 
                if (Category.ToString().Equals("MyCategory1"))
                { 
                    //get the content for editing 
                    StagedContent itemToChange = cm.GetStagedContent(item.ID) as StagedContent; 
                    //check if the Pub. Day is even or odd (2,4,6... or 1,3,5....) 
                    bool changed = false
                    if (pubDate.Day % 2 == 0) 
                    { 
                        //day is even 
                        DateTime newTime = DateTime.Today; 
                        itemToChange.SetMetaData("Publication_Date", newTime); 
                        //expire in 30 days from now on 
                        itemToChange.SetMetaData("Expiration_Date", newTime.AddDays(30)); 
                        changed = true
                    } 
                    else 
                    { 
                        //day is odd 
                        //do something else with the dates 
                        changed = true
                    } 
                    if (changed) 
                        cm.SavedStagedContent(itemToChange, ContentStatus.Published); 
                } 
            } 
     
        } 

    I hope this example will help you to achieve your needs. Please note that is not tested. I just wanted to show you the APIs.

    Best wishes,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    19 Nov 2008
    Link to this post
    Hi,

    That's great Georgi!, many thanks for the sample. I will use to manage one planing for post of GC Modules.

    Someone have other solutions to build one planning scheduling like
    TimeLine   now /--/--/--/--/--/--/--/--/--/--/--/ >          
    news1                xxxx      xxxxxxx       xxxx
    news2          xxxx      xxxx           xxxx       xxxx
    ..
    Very useful for Hotels, reservations systems, advertising?.

    Regards
Register for webinar
5 posts, 0 answered