More in this section

Forums / Developing with Sitefinity / News Code not Working from 3.7 to 3.7 SP2

News Code not Working from 3.7 to 3.7 SP2

3 posts, 0 answered
  1. Jodie
    Jodie avatar
    59 posts
    Registered:
    09 Oct 2012
    11 Jan 2010
    Link to this post
    Hi Guys, me again :)

    I've been using the code below to list all the news and their urls. But after installing 3.7 sp2 and shifting the content over this no longer works. I don't get any errors it's just displays an empty page, however in the 3.7 version which I still have, it lists all news fine. Any ideas?

        Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
            Dim pageManager As New CmsManager()  
            Dim pages As IList = pageManager.GetPages()  
            '    
            Dim newsUrls As New List(Of String)()  
            '    
            Dim vd As String = Request.AppRelativeCurrentExecutionFilePath.Replace("~", [String].Empty)  
            Dim path As String = Request.Url.AbsoluteUri.Replace(vd, String.Empty)  
     
            For Each page As IPage In pages  
                Dim controls As IList(Of ICmsWebControl) = page.Controls  
                For Each control As ICmsWebControl In controls  
                    If control.TypeName.Equals(GetType(Telerik.News.WebControls.NewsView).AssemblyQualifiedName) Then 
                        Dim newsManager As New NewsManager("News")  
                        Dim newsArticles As IList  
                        Dim nvCtrl As NewsView = TryCast(control.LoadControl(), NewsView)  
                        'load the "filtered" news articles only. Note that a blank FilterExpression is still a FilterExpression    
                        Dim filterBuilder As New ContentFilterBuilder(nvCtrl)  
                        If filterBuilder.IsFilterValid Then 
                            newsArticles = newsManager.Content.GetContent(0, Integer.MaxValue, nvCtrl.SortExpression, filterBuilder.ParseTagFilter(), ContentStatus.Published, Nothing, _  
                             filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter())  
                        Else 
                            'filter not valid. Perhaps the NewsView is showing..nothing.    
                            Continue For 
                        End If 
                        'We will take the URL from the Master control, so we could skip this NewsView if it is in    
                        'Detail behavior mode.    
                        If nvCtrl.BehaviorMode = Telerik.Cms.Engine.WebControls.ContentView.BehaviorModes.Detail Then 
                            Continue For 
                        End If 
     
                        Dim pageUrl As String 
                        'the news page could be the NewsView detail page... (e.g. NewsView is in Master/Auto mode)    
                        If nvCtrl.SingleItemUrl.Length <> 0 Then 
                            pageUrl = nvCtrl.SingleItemUrl  
                        Else 
                            Dim cmsPage As ICmsPage = TryCast(pageManager.GetPage(page.ID), ICmsPage)  
                            'we could iterate through all additional urls, now taking the default one.    
                            pageUrl = cmsPage.DefaultUrl.Url  
                        End If 
     
                        pageUrl = pageUrl.Replace(".aspx""")  
                        pageUrl = pageUrl.Replace("~""")  
                        For Each article As IContent In newsArticles  
                            'this should be url = pageUrl + article.UrlWithExtension in 3.6    
                            Dim url As String = path + pageUrl + article.Url + ".aspx" 
                            'add the url to the list    
                            If Not newsUrls.Contains(url) Then 
                                newsUrls.Add(url)  
                            End If 
                        Next 
                    End If 
     
                Next 
            Next 
            'show the urls   
     
            For Each articleUrl As String In newsUrls  
                Response.Write(articleUrl + "<br />")  
            Next 
        End Sub 

    Any help is appreciated

    Cheers

    Jodie
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Jan 2010
    Link to this post
    Hi Jodie,

    I checked the code( which is copied from this post) and it works fine under 3.7 SP2. Also there are no API changes related to GenericContent based modules.
    Make sure that you have NewsView control on a page of your website. You can attach VS debugger to the line below and see whether the code inside the if loop will be reached

    If control.TypeName.Equals(GetType(Telerik.News.WebControls.NewsView).AssemblyQualifiedName) Then


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jodie
    Jodie avatar
    59 posts
    Registered:
    09 Oct 2012
    12 Jan 2010
    Link to this post
    Hi Ivan,

    Thanks for the reply. I can confirm the NewsView was definitely on the pages, in the end all I had to do was edit then re-publish the pages with the news view on them and it worked.

    Thanks again

    Jodie
Register for webinar
3 posts, 0 answered