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.
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.
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.
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.
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
Thanks for your reply. This is my code:
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.
You need to do this after you save:
is working on a reply...