Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Beckert 193 posts 469 karma points
    Mar 16, 2016 @ 11:42
    Thomas Beckert
    0

    Access Contentservice from BackgroundWorker Class

    Hi,

    I run a BackgroundWorker Thread after the Startup-Event, that checks for Nodes with an expired Date.

     var contentService = ApplicationContext.Current.Services.ContentService;
    
                    foreach (IContent node in contentService.GetContentOfContentType(SerienTerminType.Id))
                    {
                        if (node.Status == ContentStatus.Published)
                        {
                            //DO THE MAGIC                            
                            DateTime nt = Convert.ToDateTime(node.GetValue("naechsterTermin"));
    
                            if((DateTime.Now.Date - nt).TotalDays > 0)
                            {
                                try
                                {
                                contentService.SaveAndPublishWithStatus(node,0, true);
    
                                }
                                catch(Exception ex)
                                {
                                   // Error happens
                                }
                           }
                        }
    

    The SaveAndPublish function throws an error, that the httpContext is null. In Version 7.3.x it worked. What has changed and how can I fix it?

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Mar 17, 2016 @ 07:47
    Jeroen Breuer
    100

    Hello,

    If you want to work without httpContext try the Umbraco console application example: https://github.com/sitereactor/umbraco-console-example

    Jeroen

  • Thomas Beckert 193 posts 469 karma points
    Mar 17, 2016 @ 11:49
    Thomas Beckert
    0

    Cool hint! Thnx a lot.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies