Copied to clipboard

Flag this post as spam?

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


  • David Vannay 5 posts 25 karma points
    Mar 02, 2015 @ 11:53
    David Vannay
    0

    Umbraco API and DateFolders

    Hello,

    I am creating content using Umbraco API's Document service, which should be automatically saved in DateFolders (year, month, day). When I create the content manually it is automatically saved in DateFolders, but using API it doesn't work. Is there a way to make sure that it is saved there or at least some way to do it afterwards for all of them at once?

    Thanks in advance.

    David

    p.s I have tried DateFolder and uDateFoldersy packages.

  • Jeroen Breuer 4861 posts 12139 karma points MVP 3x admin c-trib
    Mar 02, 2015 @ 12:06
    Jeroen Breuer
    0

    Hello,

    Could you post the code so we can see what might go wrong? When using the API it only works if you call UmbracoContext.Current.Application.Services.ContentService.Save(content) afterwards. 

    If you only want to use datafolders so you can have a date in the url you should read this blog: http://24days.in/umbraco/2014/urlprovider-and-contentfinder/. You can also add a date to a url programmatically.

    Jeroen

  • David Vannay 5 posts 25 karma points
    Mar 06, 2015 @ 11:43
    David Vannay
    0

    Thanks for your reply. This is my code:

    public string PostNews(string name, string postDate, string bodyText, int id, string source, int category)
        {
            // Get the Umbraco Content Service
            var contentService = ApplicationContext.Current.Services.ContentService;
            var news = contentService.CreateContent(
                name, // the title of the news
                id, // the parent id should be the id of the group node 
                "NewsPage", // the alias of the news list Document Type
                0);
    
            // We need to update properties (product id, original name and the price)
            news.SetValue("postDate", postDate);
            news.SetValue("bodyText", bodyText);
            //news.SetValue("Source", source);
            //news.SetValue("newsCategory", category);
    
            // finally we need to save and publish it (which also saves the news!) - that's done via the Content Service
    
            contentService.Save(news);
            return "success";
        }
    

    The datefolders are set to create a folders based on the postDate attribute, however, it doesn't. It does only when I click manually Save inside the Umbraco.

  • Terkel Skibby Larsen 2 posts 22 karma points
    May 30, 2015 @ 08:49
    Terkel Skibby Larsen
    0

    You need to do this after you save:

    ...
    contentService.Save(news);

    news = uDateFoldersy.DateFolderService.Instance.EnsureCorrectParentForPost(news, false);
    contentService.SaveAndPublishWithStatus(news);

     

Please Sign in or register to post replies

Write your reply to:

Draft