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

Forums / 3.x Pre-release forums (retired) / Sean Molam's sitemap.org for Sitefinity

Sean Molam's sitemap.org for Sitefinity

35 posts, 0 answered
  1. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    02 Apr 2007
    Link to this post
    Sean -

    I hope it is OK with you that I modified your code that you posted on your blog with a link from this thread.

    http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-gdkbk.aspx

    Modifications were made to use vb.net (because I'm lazy) and work with Sitefinity. Below is the .ashx file. It still needs the priority attribute, which I thought we could store as a meta tag temporarily. I have not had a chance to validate this,but it looks like a good start. In this example the CMSManager object was used in order to use the CMSPage object.
     
    Sincerely,

    Ben

    <%@ WebHandler Language="VB" Class="alightenGSM" %>  
     
    Imports System  
    Imports System.Web  
    Imports System.Collections.Specialized  
    Imports System.IO  
    Imports System.Text  
    Imports System.Xml  
    Imports Telerik.Cms  
    Imports Telerik  
    Imports System.Web.UI.WebControls  
     
    Public Class alightenGSM  
        Implements IHttpHandler  
          
        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest  
            Try 
                  
                Dim response As HttpResponse = context.Response       
                response.ContentType = "text/plain"              
              
                Dim writer As New XmlTextWriter(response.OutputStream, Encoding.UTF8)  
              
                writer.Formatting = Formatting.Indented  
                writer.WriteStartDocument()  
                writer.WriteStartElement("urlset")  
     
                'writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")  
                'writer.WriteAttributeString("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd")  
                writer.WriteAttributeString("xmlns""http://www.google.com/schemas/sitemap/0.9")  
                  
              
                'Dim root As SiteMapNode  
                'root = SiteMap.Providers("CmsSiteMapProvider").RootNode  
                Dim manager As New CmsManager  
                Dim root As Cms.RootPage = manager.GetRootPage  
                Dim pages As GetRootPages = root.Children  
                Dim page As CmsPage  
                  
                For Each page In pages  
                    If page.Navigable = True Then 
                        AppendNode(page, writer, 0)  
                    End If                  
                Next 
                  
              
                writer.WriteEndElement()  
                writer.WriteEndDocument()  
                  
                response.Flush()  
                writer.Flush()  
     
            Catch ex As Exception  
                  
            End Try 
              
        End Sub 
          
        Private Sub AppendNode(ByVal page As CmsPage, ByVal writer As XmlTextWriter, ByVal depth As Integer)  
            Try 
                Dim n As CmsPage  
                Dim subNodeDepth As Integer 
                 
                                   
                  
                writer.WriteStartElement("url")  
                writer.WriteElementString("loc", GetURL(page))  
                writer.WriteElementString("lastmod", GetLastMod(page))  
                writer.WriteElementString("changefreq", GetChangeFreq(page))  
                writer.WriteElementString("priority", GetPriority(page))  
                  
                subNodeDepth = depth + 1  
                For Each n In page.ChildPages  
                    If page.Navigable = True Then 
                        AppendNode(n, writer, subNodeDepth)  
                    End If                  
                Next 
                  
                writer.WriteEndElement()  
                  
                  
                  
                 
            Catch ex As Exception  
     
            End Try 
        End Sub 
          
        Private Function GetURL(ByVal page As CmsPage) As String 
            Try 
                Dim vars As NameValueCollection = HttpContext.Current.Request.ServerVariables  
                Dim port As String = vars("SERVER_PORT")  
                Dim protocol As String = vars("SERVER_PORT_SECURE")  
                Dim urlResolver As New System.Web.UI.Control  
                Dim url As String 
                  
                If (port Is Nothing Or port = "80" Or port = "443"Then 
                    port = "" 
                Else 
                    port = ":" + port  
                End If 
             
                If (protocol Is Nothing Or protocol = "0"Then 
                    protocol = "http://" 
                Else 
                    protocol = "https://" 
                End If 
                  
                url = page.Urls(page.DefaultUrlIndex).Url  
                Return protocol + vars("SERVER_NAME").ToString + port + urlResolver.ResolveUrl(url)  
             
            Catch ex As Exception  
                Return String.Empty  
            End Try 
        End Function 
          
        Private Function GetLastMod(ByVal page As CmsPage) As String 
            Try              
                                        
                Return page.DateModified.ToString("o")  
            Catch ex As Exception  
                Return String.Empty  
            End Try 
        End Function 
          
        Private Function GetChangeFreq(ByVal page As CmsPage) As String 
            Try           
                Dim intervalString As String = String.Empty  
                Dim intervalLong As Long = DateDiff(DateInterval.Hour, page.DateModified, Now)  
                     
                If intervalLong < 1 Then 
                    intervalString = "hourly" 
                ElseIf intervalLong <= 24 And intervalLong > 1 Then 
                    intervalString = "daily" 
                ElseIf intervalLong <= 168 And intervalLong > 24 Then 
                    intervalString = "weekly" 
                ElseIf intervalLong <= 672 And intervalLong > 168 Then 
                    intervalString = "monthly" 
                ElseIf intervalLong <= 8766 And intervalLong > 672 Then 
                    intervalString = "yearly" 
                End If                            
                  
                Return intervalString  
            Catch ex As Exception  
                Return String.Empty  
            End Try 
        End Function 
          
        Private Function GetPriority(ByVal page As CmsPage) As String 
            Try 
                  
                Return "1" 
            Catch ex As Exception  
                Return String.Empty  
            End Try 
        End Function 
       
        Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable  
            Get 
                Return True 
            End Get 
        End Property 
     
    End Class 
  2. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    02 Apr 2007
    Link to this post
    It seems to validate even with nexted nodes. Does anyone no if this allowed.

    Sincerely,

    Ben
  3. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    03 Apr 2007
    Link to this post
    Hi bnye,

    Thank you very much for the code submitted. It is great to see Sitefinity sites in google sitemap format. We will take a deeper look at it and see if we could make some improvements and ship it with one of our next releases. I am sure it will be of great help to other users as well.

    You can use the meta information for Sitefinity pages as a workaround for the priority tag . For example, you could store the priority in the content meta tag for a page. In the code, you will need to add the following for the GetPriority() method:

    Private Function GetPriority(ByVal page As CmsPage) As String  
            Try  
                For Each hCtrl As HeaderControl In page.HeaderControls  
                    For Each ctrlPr As CmsControlProperty In hCtrl.Properties  
                        If ctrlPr.Name = "Content" AndAlso Not [String].IsNullOrEmpty(ctrlPr.Value) Then  
                            Return ctrlPr.Value  
                        End If  
                    Next  
                Next  
                Return "0.5"  
            Catch ex As Exception  
                Return String.Empty  
            End Try  
        End Function 

    Also I don't think you cannot have nested url tags in a sitemap xml as the xsd validation does not allow it:
    http://www.google.com/schemas/sitemap/0.84/sitemap.xsd

    Once again, thank you very much for the code submitted. Your telerik points have been updated.

    Regards,

    Vassil Daskalov
    the telerik team


    Instantly find answers to your questions at the new telerik Support Center
  4. Sean
    Sean avatar
    271 posts
    Registered:
    31 May 2006
    04 Apr 2007
    Link to this post
    Hi Ben,

    Great post, I will definitely have to give your code a go, don't worry I can convert it back to c# if need be, I actually had both versions of it anyway as I am still slowly switching to vb.net :)  I think Telerik have a converter on their site now somewhere, or so I read on the blogs, haven't got to it yet.

    But good idea to store the priority as a content meta tag, I wish I had more time myself to have done the changes, but good to see that someone else is on the ball.

    Cheers
    Sean
  5. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    04 Apr 2007
    Link to this post
    Hi Sean,

    You can find the telerik converter here: http://converter.telerik.com/. It's great. I used it to convert the VB code from Ben's post and it was quite easy to do so. I only had to make some small but inevitable additions.

    Kind regards,
    Vassil Daskalov
    the telerik team

    Instantly find answers to your questions at the new telerik Support Center
  6. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    04 Apr 2007
    Link to this post
    Here is another GetPriority try with a Meta with attributes name = 'priority' and content = '1' or any value.

     Private Function GetPriority(ByVal page As CmsPage) As String 
            Try 
                  
                For Each hCtrl As HeaderControl In page.HeaderControls              
                    If hCtrl.Attributes.Item(1).Value.ToUpper = "Priority".ToUpper AndAlso Not [String].IsNullOrEmpty(hCtrl.Attributes.Item(0).Value) Then 
                        Return hCtrl.Attributes.Item(0).Value  
                    End If 
                Next 
                  
                Return "0.5" 
     
            Catch ex As Exception  
                Return String.Empty  
            End Try 
        End Function 


  7. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    04 Apr 2007
    Link to this post
    How can I get  a list of the News items that have not expired? Is this done throug the NewsManager? I guess without adding blog, news and other custom items to the sitemap it would be a bit useless.
  8. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    05 Apr 2007
    Link to this post
    sorry for the barrage of posts. However, if I do a date format of "yyyyy-MM-ddThh:mm:zzzzzz the time zone seems to be off by 1 hour. Yes, I have the latest MS patch for Date time installed. Strange.

    Sincerely,

    Ben
  9. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    05 Apr 2007
    Link to this post
    Hello Ben,

    To take all news which have not expired yet or are not published (i.e. the publication date is bigger than DateTime.Now) try this code:

    Private Function GetRealNews(ByVal newsProvider As StringAs IList  
        Dim contentManager As New ContentManager(newsProvider)  
     
        Dim parm1 As New MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Now, SearchCondition.LessOrEqual)  
        Dim parm2 As New MetaSearchInfo(MetaValueTypes.DateTime, "Expiration_Date", DateTime.Now, SearchCondition.GreaterThen, JoinType.[Or])  
        Return contentManager.GetContent(0, 0, "", parm1, parm2)  
    End Function 
     

    I am not sure I understand you right about your second post. Could you give us some more information about the situation in which you see this problem. I cannot find any problems with the time saving and retrieving connected to content manager. I also want to let you know that when the time is saving, it is converted to universal time but when it is retrieving it must be converted to local time. Everything on this matter seems to be ok for the content manager.

    Kind regards,
    Vassil Daskalov
    the telerik team

    Instantly find answers to your questions at the new telerik Support Center
  10. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    05 Apr 2007
    Link to this post
    That is perfect regarding the news.

    For the second post, I was just wondering why Nolics is date stamping the page.DateModified with the incorrect timezone. This server shows the correct timezone.

    Sincerely,

    Ben
  11. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    06 Apr 2007
    Link to this post
    Hello Ben,

    How do you retrieve the data from the database? In case your retrieve it with query directly from the database you must convert it to local time before operating with it due to the fact that it is saved to universal time in the database. In case you use Sitefinity DateTime property such as page.DateModified you do not need to make any conversions as Sitefinity takes care for the conversion itself. This conversion is not connected with Nolics. It is our implementation.

    Could you provide us with more specific example so we can sure that we are talking about the same situation?

    Thanks in advance and sorry for the inconvenience.

    Kind regards,
    Vassil Daskalov
    the telerik team

    Instantly find answers to your questions at the new telerik Support Center
  12. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    06 Apr 2007
    Link to this post

    The standard pages using page.DateModified are also showing up with the incorrect date.

    I opened a support ticket on this one. Thanks for your help.

  13. Matt
    Matt avatar
    22 posts
    Registered:
    25 Jan 2008
    26 May 2009
    Link to this post
    On the news module portion: I'm missing something here. ProcessRequest loops for all CmsPages, but the GetRealNews function supplied works off Content. I thought I had done this conversion before, but I can't seem to find it. Can I trouble someone for a sample of the call to GetRealNews? Thanks!
  14. Pepi
    Pepi avatar
    981 posts
    Registered:
    16 Sep 2016
    27 May 2009
    Link to this post
    Hi Matt,

    Please open a new support ticket and explain in details what functionality you need. Also, which version of Sitefinity are you using? Note that this thread is very old and the provided examples are not up to date.

    Thanks for your cooperation in advance.

    Regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  15. Brandon
    Brandon avatar
    3 posts
    Registered:
    26 Jun 2007
    15 Jun 2009
    Link to this post
    Hi there Sitefinity community - new user, looking to add this functionality - is there a definitive post/howto/etc on this subject?  (initial link in post leads to another post with no code) - and this one, while great - isn't helping me too much

    Thanks 
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    30 Sep 2016
    15 Jun 2009
    Link to this post
    Hello Matthew Tamm,

    You can take a look at Sitefinity API, since the thread is an year old and the samples are not up do date.

    Overview of Generic Content API
    News API Overview

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  17. Matt
    Matt avatar
    22 posts
    Registered:
    25 Jan 2008
    15 Jun 2009
    Link to this post
    I know this is old and out of date, but here's what I've been using. It's a combination of the code posted on these threads, plus a bit to work with the news module. If nothing else, it might help get you started.

    <%@ WebHandler Language="VB" class="sitemap" %>   
    Imports System   
    Imports System.Web   
    Imports System.IO   
    Imports System.Text   
    Imports System.Xml   
      
    Imports Telerik.Search   
    Imports Telerik.Cms   
    Imports Telerik.Cms.data   
    Imports Telerik   
    Imports Telerik.Cms.Engine   
      
    Imports Lucene.Net.Documents   
    Imports Lucene.Net.Search   
    Imports Telerik.News 
      
      
    Public Class sitemap 
        Implements IHttpHandler 
           
           
           
        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest 
            Try 
                   
                Dim response As HttpResponse = context.Response 
                response.ContentType = "text/plain" 
               
                Dim writer As New XmlTextWriter(response.OutputStream, Encoding.UTF8) 
               
                writer.Formatting = Formatting.Indented 
                writer.WriteStartDocument() 
                writer.WriteStartElement("urlset"
                   
                writer.WriteAttributeString("xmlns""http://www.sitemaps.org/schemas/sitemap/0.9"
                                                                                                    
                   
                Dim pages As New GetCmsPages 
                pages.LoadAll() 
                 
                For Each page As CmsPage In pages 
                    If page.Status = PageStatus.Published = True Then 
                        AppendNode(page, writer, 0) 
                    End If 
                Next 
                   
                AppendNews(writer, 0) 
                 
                writer.WriteEndElement() 
                writer.WriteEndDocument() 
                   
                response.Flush() 
                writer.Flush() 
      
            Catch ex As Exception 
                   
            End Try 
               
        End Sub 
           
        Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable 
            Get 
                Return True 
            End Get 
        End Property 
      
      
        Private Sub AppendNode(ByVal page As CmsPage, ByVal writer As XmlTextWriter, ByVal depth As Integer
           
            Try 
                writer.WriteStartElement("url"
                writer.WriteElementString("loc", GetURL(page)) 
                writer.WriteElementString("lastmod", GetLastMod(page)) 
                writer.WriteElementString("changefreq", GetChangeFreq(page)) 
                writer.WriteElementString("priority", GetPriority(page)) 
                   
                writer.WriteEndElement() 
     
            Catch ex As Exception 
      
            End Try 
        End Sub 
           
        Private Function GetURL(ByVal page As CmsPage) As String 
            Try 
                Dim vars As NameValueCollection = HttpContext.Current.Request.ServerVariables 
                Dim port As String = vars("SERVER_PORT"
                Dim protocol As String = vars("SERVER_PORT_SECURE"
                Dim urlResolver As New System.Web.UI.Control 
                Dim url As String 
                   
                If (port Is Nothing Or port = "80" Or port = "443"Then 
                    port = "" 
                Else 
                    port = ":" + port 
                End If 
              
                If (protocol Is Nothing Or protocol = "0"Then 
                    protocol = "http://" 
                Else 
                    protocol = "https://" 
                End If 
                            
                url = page.DefaultUrl.Url 
                Return protocol + vars("SERVER_NAME").ToString + port + urlResolver.ResolveUrl(url) 
              
            Catch ex As Exception 
                Return String.Empty 
            End Try 
        End Function 
           
        Private Function GetLastMod(ByVal page As CmsPage) As String 
            Try 
                                         
                Return Format(page.DateModified, "yyyyy-MM-ddThh:mm:sszzzz"
            Catch ex As Exception 
                Return String.Empty 
            End Try 
        End Function 
           
        Private Function GetChangeFreq(ByVal page As CmsPage) As String 
            Try 
                Dim intervalString As String = String.Empty 
                Dim intervalLong As Long = DateDiff(DateInterval.Hour, page.DateModified, Now) 
                      
                If intervalLong < 1 Then 
                    intervalString = "hourly" 
                ElseIf intervalLong <= 24 And intervalLong > 1 Then 
                    intervalString = "daily" 
                ElseIf intervalLong <= 168 And intervalLong > 24 Then 
                    intervalString = "weekly" 
                ElseIf intervalLong <= 672 And intervalLong > 168 Then 
                    intervalString = "monthly" 
                ElseIf intervalLong <= 8766 And intervalLong > 672 Then 
                    intervalString = "yearly" 
                End If 
                   
                Return intervalString 
            Catch ex As Exception 
                Return String.Empty 
            End Try 
        End Function 
              
        Private Function GetPriority(ByVal page As CmsPage) As String 
            Try 
                For Each hCtrl As HeaderControl In page.HeaderControls 
                    For Each ctrlPr As CmsControlProperty In hCtrl.Properties 
                        If ctrlPr.Name = "Content" AndAlso Not [String].IsNullOrEmpty(ctrlPr.Value) Then 
                            Return ctrlPr.Value 
                        End If 
                    Next 
                Next 
                Return "0.5" 
            Catch ex As Exception 
                Return String.Empty 
            End Try 
        End Function 
         
        Private Sub AppendNews(ByVal writer As XmlTextWriter, ByVal depth As Integer
            Try 
                                               
                Dim m As New NewsManager("News"
                Dim items As IList = m.Content.GetContent() 
                For Each item As IContent In items 
                            
                    writer.WriteStartElement("url"
                    writer.WriteElementString("loc""http://www.medicalteams.org/sf/LearnAboutUs/newsroom/article" + item.UrlWithExtension) 
                    writer.WriteElementString("lastmod", item.DateModified) 
                     
                    Dim intervalString As String = String.Empty 
                    Dim intervalLong As Long = DateDiff(DateInterval.Hour, item.DateModified, Now) 
                      
                    If intervalLong < 1 Then 
                        intervalString = "hourly" 
                    ElseIf intervalLong <= 24 And intervalLong > 1 Then 
                        intervalString = "daily" 
                    ElseIf intervalLong <= 168 And intervalLong > 24 Then 
                        intervalString = "weekly" 
                    ElseIf intervalLong <= 672 And intervalLong > 168 Then 
                        intervalString = "monthly" 
                    ElseIf intervalLong <= 8766 And intervalLong > 672 Then 
                        intervalString = "yearly" 
                    End If 
                     
                    writer.WriteElementString("changefreq", intervalString) 
                    writer.WriteElementString("priority""0.5"
                   
                    writer.WriteEndElement() 
                     
                Next 
                 
            Catch ex As Exception 
      
            End Try 
        End Sub 
         
    End Class  

  18. Georgi
    Georgi avatar
    3583 posts
    Registered:
    20 Sep 2016
    16 Jun 2009
    Link to this post
    Hello Matt,

    Thank you for posting your approach. We are currently thinking for including the news and blog post in the Sitemap, since their pages are created dynamically by the NewsView controls (they are not included in the Sitemap).

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  19. Brandon
    Brandon avatar
    3 posts
    Registered:
    26 Jun 2007
    16 Jun 2009
    Link to this post

    Hi again Sitefinity forum - thanks for the input; got it all working well for me (for now) - I think  ;-)

    Here it is in c# (with some small mods for my style) for the next person to refine

    thanks again

    Matthew


    using System; 
    using System.Web; 
    using System.IO; 
    using System.Text; 
    using System.Xml; 
    using System.Collections; 
    using System.Collections.Generic; 
    using System.Collections.Specialized; 
     
    using Telerik.Search; 
    using Telerik.Cms; 
    using Telerik.Cms.Web; 
    using Telerik.Cms.Data; 
    using Telerik.Cms.Engine; 
    using Telerik; 
    using Telerik.News; 
    using Telerik.News.Data; 
    using Telerik.Sitefinity; 
     
     
    public class GoogleSiteMap : IHttpHandler 
        public void ProcessRequest ( HttpContext context ) 
        { 
            try 
            { 
                // the request 
                HttpResponse response = context.Response; 
                response.ContentType = "text/plain"
     
                // the writer to create the xml file in 
                XmlTextWriter writer = new XmlTextWriter( response.OutputStream, Encoding.UTF8 ); 
     
                // start writing 
                writer.Formatting = Formatting.Indented; 
                writer.WriteStartDocument( ); 
                writer.WriteStartElement( "urlset" ); 
                writer.WriteAttributeString( "xmlns""http://www.sitemaps.org/schemas/sitemap/0.9" ); 
     
                // add news 
                AppendNews( writer ); 
     
                // add pages 
                AppendPages( writer ); 
     
                // finish 
                writer.WriteEndElement( ); 
                writer.WriteEndDocument( ); 
     
                // and flush to client 
                response.Flush( ); 
                writer.Flush( ); 
            } 
            catch 
            { 
                throw
            } 
        } 
     
        public bool IsReusable 
        { 
            get { return true; } 
        } 
     
        private void AppendPages ( XmlTextWriter writer ) 
        { 
            // get a pages object 
            GetCmsPages pages = new GetCmsPages( ); 
            // and load em all up 
            pages.LoadAll( ); 
            // process each page 
            foreach ( CmsPage page in pages ) 
                if ( page.Status == PageStatus.Published == true ) 
                    AppendNode( page, writer, 0 ); 
        } 
     
        private void AppendNews ( XmlTextWriter writer ) 
        { 
            // values we need 
            string url = string.Empty; 
            string lastModified = string.Empty; 
            string changeFrequency = string.Empty; 
            string priority = string.Empty; 
     
            // the news viewer page (this value is stored in the web.config appSettings ) 
            IPage page = new CmsManager( ).GetPage( Common.NewsPageViewerPageUid ); 
     
            // the url of the page (string off the .aspx extension) 
            string baseNewsViewerUrl = GetURL( ( (CmsPage)page ).DefaultUrl.Url ).Replace( ".aspx""" ); 
     
            // get active news articles 
            IList articles = new NewsManager( "News" ).Content.GetContent( 
                    0, 
                    0, 
                    new MetaSearchInfo( MetaValueTypes.DateTime, "Publication_Date", DateTime.Now, SearchCondition.LessOrEqual ), 
                    new MetaSearchInfo( MetaValueTypes.DateTime, "Expiration_Date", DateTime.Now, SearchCondition.GreaterThen, JoinType.Or ) 
                ); 
     
            // process each item         
            foreach ( IContent article in articles ) 
            { 
                // if not published then skip 
                if ( article.Status != ContentStatus.Published ) 
                    continue
     
                url = string.Concat( baseNewsViewerUrl, article.Url.ToString( ) ); 
                lastModified = GetLastModifiedDate( article.DateModified ); 
                changeFrequency = GetChangeFrequency( article.DateModified ); 
                // default on news pages 
                priority = "0.5"
     
                // add element to writer 
                AppendUrlElement( writer, url, lastModified, changeFrequency, priority ); 
            } 
        } 
     
        private void AppendNode ( CmsPage page, XmlTextWriter writer, int depth ) 
        { 
     
            try 
            { 
                // in to deep? 
                int subNodeDepth = 0; 
     
                // values we need 
                string url = GetURL( page.DefaultUrl.Url ); 
                string lastModified = GetLastModifiedDate( page.DateModified ); 
                string changeFrequency = GetChangeFrequency( page.DateModified ); 
                // always return a max priority for the home page,  
                string priority = ( page.ID == new UrlHelper.HomePageInfo( ).ID ) ? "1.0" : GetPriority( page ); 
     
                // add element to writer 
                AppendUrlElement( writer, url, lastModified, changeFrequency, priority ); 
     
                // how deep can we go? 
                subNodeDepth = depth + 1; 
     
                // process each sub page 
                foreach ( CmsPage cmsPage in page.ChildPages ) 
                    if ( page.Navigable == true ) 
                        AppendNode( cmsPage, writer, subNodeDepth ); 
            } 
     
            catch 
            { 
                // fail silently? 
            } 
        } 
     
        private void AppendUrlElement ( XmlTextWriter writer, string url, string lastModified, string changeFrequency, string priority ) 
        { 
            writer.WriteStartElement( "url" ); 
            writer.WriteElementString( "loc", url ); 
            writer.WriteElementString( "lastmod", lastModified ); 
            writer.WriteElementString( "changefreq", changeFrequency ); 
            writer.WriteElementString( "priority", priority ); 
            writer.WriteEndElement( ); 
        } 
     
        private string GetURL ( string url ) 
        { 
            try 
            { 
                NameValueCollection vars = HttpContext.Current.Request.ServerVariables; 
                string port = vars[ "SERVER_PORT" ]; 
                string protocol = vars[ "SERVER_PORT_SECURE" ]; 
                System.Web.UI.Control urlResolver = new System.Web.UI.Control( ); 
     
                if ( ( port == null | port == "80" | port == "443" ) ) 
                { 
                    port = ""
                } 
                else 
                { 
                    port = ":" + port; 
                } 
     
                if ( ( protocol == null | protocol == "0" ) ) 
                { 
                    protocol = "http://"
                } 
                else 
                { 
                    protocol = "https://"
                } 
     
                return protocol + vars[ "SERVER_NAME" ].ToString( ) + port + urlResolver.ResolveUrl( url ); 
            } 
     
            catch 
            { 
                return string.Empty; 
            } 
        } 
     
        private string GetLastModifiedDate ( DateTime dateModified ) 
        { 
            try 
            { 
                return dateModified.ToString( "yyyy-MM-ddThh:mm:sszzzz" ); 
            } 
            catch 
            { 
                return string.Empty; 
            } 
        } 
     
        private string GetChangeFrequency ( DateTime lastModified ) 
        { 
            string defaultValue = "weekly"
     
            try 
            { 
                int intervalLong = DateTime.Today.Subtract( lastModified ).Hours; 
     
                if ( intervalLong < 1 ) 
                    return "hourly"
                else if ( intervalLong <= 24 & intervalLong > 1 ) 
                    return "daily"
                else if ( intervalLong <= 168 & intervalLong > 24 ) 
                    return "weekly"
                else if ( intervalLong <= 672 & intervalLong > 168 ) 
                    return "monthly"
                else if ( intervalLong <= 8766 & intervalLong > 672 ) 
                    return "yearly"
     
                // here? default 
                return defaultValue; 
            } 
            catch 
            { 
                return defaultValue; 
            } 
        } 
     
        private string GetPriority ( CmsPage page ) 
        { 
            // if no specific value or an exception condition, retrun the default 
            string defaultValue = "0.5"
     
            try 
            { 
                foreach ( HeaderControl headerControl in page.HeaderControls ) 
                    foreach ( CmsControlProperty controlProperty in headerControl.Properties ) 
                        if ( controlProperty.Name == "Content" && !String.IsNullOrEmpty( controlProperty.Value ) ) 
                            return controlProperty.Value; 
     
                return defaultValue; 
            } 
            catch 
            { 
                return defaultValue; 
            } 
        } 
  20. Georgi
    Georgi avatar
    3583 posts
    Registered:
    20 Sep 2016
    16 Jun 2009
    Link to this post
    Hi Matthew and Matt ,

    It will be great to have your codes in our Code Library (coming very soon). What do you say about that? ;)

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  21. Matt
    Matt avatar
    22 posts
    Registered:
    25 Jan 2008
    16 Jun 2009
    Link to this post
    Ha! I should have cleaned my code up a little more...

    Everything I have is based on Ben's earlier work, so he gets credit. I only added news module support and a couple tweaks. Matthew obviously took it a step further. If it helps anyone else out, that's great. I just want to give credit where it's due.

    And, yes, news/blogs in the sitemap would be great!
  22. Georgi
    Georgi avatar
    3583 posts
    Registered:
    20 Sep 2016
    17 Jun 2009
    Link to this post
    Hi,

    Once we release the Code Library, everyone will be able to submit code. Don't worry if the code is not that cleaned up - the example is with higher importance, than the clear code :)

    Thank you for your commitment to help!

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  23. OC
    OC avatar
    129 posts
    Registered:
    17 Nov 2004
    26 Jun 2009
    Link to this post
    Hi Matt, and thanks for this code!

    But I can't get it working. Visual Studio reports that it can't find any reference to "Common" in this line:

    IPage

     

    page = new CmsManager( ).GetPage( Common.NewsPageViewerPageUid );

    Is this some of your own code, or in what assambly/namespace can it be found?

    OC

     

  24. OC
    OC avatar
    129 posts
    Registered:
    17 Nov 2004
    26 Jun 2009
    Link to this post
    Sorry, my mistace - it's just a matter of reading the comments in the file...

    Found it.

    Thanks :-)

    OC
  25. Georgi
    Georgi avatar
    3583 posts
    Registered:
    20 Sep 2016
    26 Jun 2009
    Link to this post
    Hi,

    I just want to mention that we have published a way to get the URLs for the Generic Content based articles (News, Blogs, Events), perhaps someone might need this information included in the sitemap as well.

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  26. Juliano Araujo
    Juliano Araujo avatar
    2 posts
    Registered:
    03 Mar 2009
    15 Jul 2009
    Link to this post

    Visual Studio reports that it can't find any reference to "Common" in this line:

    IPage

     

    page = new CmsManager().GetPage(Common.NewsPageViewerPageUid);

    Could somebody help please?

     

  27. Brandon
    Brandon avatar
    3 posts
    Registered:
    26 Jun 2007
    15 Jul 2009
    Link to this post
    Hi there,

    the line, and the comment above it, indicate what I am doing here..

    // the news viewer page (this value is stored in the web.config appSettings ) 
    IPage page = new CmsManager( ).GetPage( Common.NewsPageViewerPageUid );

    In a class called Common I have a static property called NewsPageViewerPageUid that is the Guid of the generic viewer for news items in my setup - you will have to change/implement this logic however best works for your situation?  This may be as simple as coding that value here (note this is a quick reply, untested):
    IPage page = new CmsManager( ).GetPage( Guid.Parse ( "{FABF44F6-7D35-418E-8FA8-62D2B8120DAC}" ) );

    Hope this helps

    Matthew
  28. Shelley
    Shelley avatar
    4 posts
    Registered:
    24 Feb 2009
    16 Jul 2009
    Link to this post
    Is there a way to modify this code to allow the user to enter in a live website URL and have it run off of that? I have multiple Sitefinity websites and I would like to use this code from one central location instead of running it from within each of my sites.

    <%@ WebHandler Language="C#" Class="SiteMap" %>

    using System;

    using System.Web;

    using System.IO;

    using System.Text;

    using System.Xml;

    using System.Collections.Specialized;

    using Telerik.Search;

    using Telerik.Cms;

    using Telerik.Cms.Data;

    using Telerik;

    using Telerik.Cms.Engine;

    using Lucene.Net.Documents;

    using Lucene.Net.Search;

    public class SiteMap : IHttpHandler

    {

    public void ProcessRequest(HttpContext context)

    {

    try {

    HttpResponse response = context.Response;

    response.ContentType = "text/plain";

    XmlTextWriter writer = new XmlTextWriter(response.OutputStream, Encoding.UTF8);

    writer.Formatting = Formatting.Indented;

    writer.WriteStartDocument();

    writer.WriteStartElement("urlset");

    writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");

    GetCmsPages pages = new GetCmsPages();

    pages.LoadAll();

    //Use this part for your custom modules  

    //pages = AppendTestimonials(pages)  

    //pages = AppendNews(pages)  

    foreach (CmsPage page in pages) {

    if (page.Status == PageStatus.Published == true) {

    AppendNode(page, writer, 0);

    }

    }

    writer.WriteEndElement();

    writer.WriteEndDocument();

    response.Flush();

    writer.Flush();

    }

    catch (Exception ex) {

    }

    }

    public bool IsReusable {

    get { return true; }

    }

    private void AppendNode(CmsPage page, XmlTextWriter writer, int depth)

    {

    try {

    int subNodeDepth;

    string pageURL = GetURL(page);

    // Check to see if the URL contains "_test", skip it if it does.

    if (pageURL.Contains("_test") == false) {

    writer.WriteStartElement("url");

    writer.WriteElementString("loc", pageURL);

    writer.WriteElementString("lastmod", GetLastMod(page));

    writer.WriteElementString("changefreq", GetChangeFreq(page));

    writer.WriteElementString("priority", GetPriority(page));

    writer.WriteEndElement();

    subNodeDepth = depth + 1;

    //Not needed because get all pages is called at the beginning.  

    foreach (CmsPage n in page.ChildPages) {

    if (page.Navigable == true) {

    AppendNode(n, writer, subNodeDepth);

    } // End if

    } // End foreach

    } // End if

    } // End try

    catch (Exception ex) {

    } // End catch

    }

    private string GetURL(CmsPage page)

    {

    try {

    NameValueCollection vars = HttpContext.Current.Request.ServerVariables;

    string port = vars["SERVER_PORT"].ToString();

    string protocol = vars["SERVER_PORT_SECURE"].ToString();

    string server = vars["SERVER_NAME"].ToString();

    System.Web.UI.Control urlResolver = new System.Web.UI.Control();

    string url;

    if ((port == null | port == "80" | port == "443")) {

    port = "";

    }

    else {

    port = ":" + port;

    }

    if ((protocol == null | protocol == "0")) {

    protocol = "http://";

    }

    else {

    protocol = "https://";

    }

    url = page.DefaultUrl.Url;

    return protocol + vars["SERVER_NAME"].ToString() + port + urlResolver.ResolveUrl(url);

    }

    catch (Exception ex) {

    return string.Empty;

    }

    }

    private string GetLastMod(CmsPage page)

    {

    try {

    return String.Format("{0:yyyy-MM-ddThh:mm:sszzzz}", page.DateModified);

    }

    catch (Exception ex) {

    return string.Empty;

    }

    }

    private string GetChangeFreq(CmsPage page)

    {

    try {

    string intervalString = string.Empty;

    DateTime dtStart = page.DateModified;

    DateTime dtEnd = DateTime.Now;

    TimeSpan tx = dtEnd - dtStart;

    long intervalLong = System.Convert.ToInt64(tx.TotalHours);

    if (intervalLong < 1) 

    intervalString = "hourly";

    else if (intervalLong <= 24 & intervalLong > 1)

    intervalString = "daily";

    else if (intervalLong <= 168 & intervalLong > 24)

    intervalString = "weekly";

    else if (intervalLong <= 672 & intervalLong > 168)

    intervalString = "monthly";

    else if (intervalLong <= 8766 & intervalLong > 672)

    intervalString = "yearly";

    return intervalString;

    }

    catch (Exception ex) {

    return string.Empty;

    }

    }

    private string GetPriority(CmsPage page)

    {

    try {

    return "0.5";

    }

    catch (Exception ex) {

    return string.Empty;

    }

    }

    }

  29. Richard
    Richard avatar
    16 posts
    Registered:
    14 Apr 2009
    16 Jul 2009
    Link to this post
    So what do I have to do to get this to work in Sitefinity?

    I created the GoogleSiteMapHandler.ashx file in my App_Code folder, but what do I have to add to web.config?

    thanks

    Richard
  30. Shelley
    Shelley avatar
    4 posts
    Registered:
    24 Feb 2009
    17 Jul 2009
    Link to this post
    Richard - I run the ashx just like a normal webpage and it displays the sitemap in your web browser. I did not add anything to web.config.
Register for webinar
35 posts, 0 answered
1 2