Error after creating a News item

Posted by Community Admin on 05-Aug-2018 17:51

Error after creating a News item

All Replies

Posted by Community Admin on 20-Aug-2010 00:00

Hello again,

I have a problem when creating a news item from code. Following this example:

http://www.sitefinity.com/40/help/developer-manual/modules-built-in-modules-api-news-creating-news-content.html

I have this code

var newsManager = NewsManager.GetManager();
newsManager.Provider.SuppressSecurityChecks = true;
  
var news = newsManager.CreateNewsItem();
news.Author = "John Smith";
news.Content = "This is some sample content.";
news.Summary = "Sumary";
news.Title = "News Item";
news.SourceName = "None";
news.DateCreated = DateTime.Now;
news.PublicationDate = DateTime.Now;
news.ExpirationDate = DateTime.Now.AddMonths(1);
  
newsManager.RecompileItemUrls<NewsItem>(news);
newsManager.Publish(news);
newsManager.SaveChanges();


It executes ok, then I can see the new item in Contents->News in the administration. But then I click on the item to edit it and I get this error (error1.png). You see there is no title, nor contents here. Then I click "Back to all items" and I get second error (error2.png) and I can no longer see the item in the list. I have to go and delete manually database records in order to clear the news list.

I suppose it might have something to do with security and permissions, but there are no examples on how to use it.

Regards,
Lupi

Posted by Community Admin on 20-Aug-2010 00:00

Never mind. I had to set the Owner property of the NewsItem.


Also, on a side note, when creating a PageTemplate, remember to set its Category like this -

template.Category = SiteInitializer.CustomTemplatesCategoryId;

or you get a nasty exception.

Posted by Community Admin on 27-Apr-2011 00:00

Hi,

After the upgrade to 4.1 my news module does not work very well any more (see attached image).

I changed the label of the 'SourceName' field and it gets Invalid resource.

Also, I need to hide the whole URL field but from the Templates it can not be done.

Thanks,
Andrei

This thread is closed