I'm developing a package for Umbraco which allows backoffice users to export blogs into xml format. However for some reason my list method which stores the values from the ContentService is storing the correct values, however it's also storing null values.
Here is my method, perhaps someone could tell me why this might be doing what it is:
public List<BlogPosts> getPostList()
{
var contentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType("umbNewsItem");
var nodes = ApplicationContext.Current.Services.ContentService.GetContentOfContentType(contentType.Id).Select(content => new Node(content.Id));
return nodes.Select(node => new BlogPosts()
{
Id = node.Id,
Title = node.GetProperty("title").ToNullSafeString(),
BodyText = node.GetProperty("bodyText").ToNullSafeString(),
PublishDate = node.GetProperty("publishDate").ToNullSafeString(),
Author = node.GetProperty("author").ToNullSafeString(),
Image = node.GetProperty("image").ToNullSafeString()
}).ToList();
}
Thanks in advance!
please note:
Before suggesting using .Value in my GetProperty statements, that throws a nullreference error saying
Object reference not set to an instance of an object
For the same package I developed an import class and when I thought it wasn't working, it was, it just wasn't working properly so there were blogposts being saved on the database unpublished but weren't on the backoffice. That I'll ask about in a different question. But to save that from causing issues in the export part of the package this was my solution:
var xEle = new XElement("Blogs",
from blog in BlogPostList
where blog.Title != null
where blog.BodyText != null
where blog.Author != null
where blog.Image != null
where blog.PublishDate != null
select new XElement("Blog",
new XAttribute("Title", blog.Title),
new XAttribute("BodyText", blog.BodyText),
new XAttribute("PublishDate", blog.PublishDate),
new XAttribute("Author", blog.Author),
new XAttribute("Image", blog.Image))
);
ContentService returning null values
I'm developing a package for Umbraco which allows backoffice users to export blogs into xml format. However for some reason my list method which stores the values from the ContentService is storing the correct values, however it's also storing null values.
Here is my method, perhaps someone could tell me why this might be doing what it is:
Thanks in advance!
please note:
Before suggesting using .Value in my GetProperty statements, that throws a nullreference error saying
Object reference not set to an instance of an object
Found the answer:
For the same package I developed an import class and when I thought it wasn't working, it was, it just wasn't working properly so there were blogposts being saved on the database unpublished but weren't on the backoffice. That I'll ask about in a different question. But to save that from causing issues in the export part of the package this was my solution:
is working on a reply...