1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / NewsManager , some question...

NewsManager , some question...

6 posts, 0 answered
  1. Paolo
    Paolo avatar
    147 posts
    Registered:
    11 Jun 2009
    23 Nov 2010
    Link to this post
    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


  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    24 Nov 2010
    Link to this post
    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
  3. Jmr
    Jmr avatar
    53 posts
    Registered:
    21 Jan 2011
    09 Feb 2011
    Link to this post
    Hi,
    How do i set AutoGenerateUniqueUrl while create custom blog post using fluent API.
    Thanks
    jmr
    
    
    
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Feb 2011
    Link to this post
    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
  5. Nikolay
    Nikolay avatar
    1 posts
    Registered:
    11 Mar 2011
    29 Apr 2011
    Link to this post
    Hi, how to set categories in this example code
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 May 2011
    Link to this post
    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
6 posts, 0 answered