NewsManager , some question...

Posted by Community Admin on 03-Aug-2018 16:55

NewsManager , some question...

All Replies

Posted by Community Admin on 23-Nov-2010 00:00

Hello,
I'm tring to use the newsmanager (since I need some user to write the news and the others only to read them)... I've written this test application :

NewsManager newsManager = new NewsManager();
           NewsItem newsItem = newsManager.CreateNewsItem(Guid.NewGuid());
           newsItem.ApplicationName = "/News";
           newsItem.Content = "Test news";
           newsItem.Author = "Paolo";
           newsItem.Title = "Paolo's";
           newsItem.Summary = "Prova inserimento url";
           newsItem.UrlName.Value = "newsprovaurl";
           newsItem.DateCreated = DateTime.Now.Date;
           //newsItem.AutoGenerateUniqueUrl = true;
           newsItem.AllowComments = false;
           newsManager.RecompileItemUrls(newsItem);
newsManager.Publish(newsItem);
newsManager.SaveChanges();

My questions are :

My news aren't published till I manually go to the page and publish dem (even if I use the publish method)
Why can't I set the AutoGenerateUniqueUrl to true?

I got this error message when I try to load the page that contains the news

The item does not have default url.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.IO.InvalidDataException: The item does not have default url.
 
Source Error:
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Why?
Thanks


Posted by Community Admin on 24-Nov-2010 00:00

Hello Paolo,

Thank you for using our services.

The UrlName property needs to be set before you publish the item. you can try this code bellow:

public void CreateNews(string newsTitle, string newsContent, string author)
    //Initializing the NewsManager with the default News provider
    NewsManager manager = NewsManager.GetManager();
 
    //creating a new news item
    NewsItem item = manager.CreateNewsItem();
 
    //setting the item's properties, content, etc.
    item.Title = newsTitle;
    item.Author = author;
    item.Content = newsContent;
    item.UrlName = "native-api";
 
     
    item.ApprovalWorkflowState = "Published";
 
    //generate URL and save changes
    manager.RecompileItemUrls<NewsItem>(item);
     
    //up to now, the item is in Draft State. We have to call Publish method to publish it.
    item = manager.Publish(item);
    manager.SaveChanges();

If you want the UrlName property to be automatically generated you can use the Fluent API approach:
public NewsItem CreateNewsItemFluent(string newsTitle, string newsContent, string author)
    
    var item = App.WorkWith().NewsItem().CreateNew()
                   .Do(nI =>
                   
                       nI.Title = newsTitle;
                       nI.Author = author;
                       nI.Content = newsContent;
                   )
                    //without the publish method, the news item is saved as draft.  
                     .Publish()
                     .SaveAndContinue().Get();
    return item;


All the best,
Radoslav Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 09-Feb-2011 00:00

Hi,
How do i set AutoGenerateUniqueUrl while create custom blog post using fluent API.
Thanks
jmr


Posted by Community Admin on 09-Feb-2011 00:00

Hi Paolo,

AutoGenerateUniqueUrl does not have a setter. You should use the code blow

          var parentID = new Guid("2230ac16-4cd1-4e8f-b45b-51ac13c7c968");
           var fluent = App.WorkWith();
           Guid DynamicGuid = Guid.NewGuid();
           var blog = fluent.Blog(parentID)
                                     .Get();
              fluent.BlogPost().CreateNew()
                                       .Do(bp =>
                                          
                                               bp.Parent = blog;
                                               bp.Title = DynamicGuid.ToString();
                                               bp.Content = "somecontent";
                                               bp.Description = "somedesc";
                                               bp.DateCreated = DateTime.UtcNow;
                                               bp.PublicationDate = DateTime.UtcNow.AddDays(10);
                                           )
                                           .SaveChanges();



All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

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

Hi, how to set categories in this example code

Posted by Community Admin on 03-May-2011 00:00

Hello,

There is a data extension method

SetValue that you can use

1. Add reference to Telerik.Sitefinity.Model  ( using Telerik.Sitefinity.Model;)

2. Call mynews.SetValue("Category", "name of existing category");



All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed