Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

XML Site Map

Posted on October 17, 2013October 26, 2015 By David Kittell
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="generateXML.aspx.vb" Inherits="Examples_generateXML" %>

<%@ Register Assembly="Ektron.Cms.Controls" Namespace="Ektron.Cms.Controls" TagPrefix="CMS" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Generate Sitemap Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Button runat="server" ID="btnGenerate" Text="Click to Generate Sitemap" OnClientClick="displayWait()" />
		<br />
		<br />
		<cms:login runat="server" id="login1" />
	</div>
	<div id="results" runat="server">
	</div>
	</form>
</body>
</html>
Imports System.Xml
Imports System.Text
Imports Ektron.Cms.WebSearch.SearchData
Imports Ektron.Cms.API.Search
Imports Ektron.Cms.CommonApi
Imports System.Data.SqlClient

Partial Class Examples_generateXML
Inherits System.Web.UI.Page

Public Shared connString As String = ConfigurationManager.ConnectionStrings("Ektron.DbConnection").ToString()
Public Shared sUserID As String = ""

#Region "Get Asset data from SQL - Start"
#Region "Get full file name data from SQL - Start"
Public Function sGetFileName(ByVal contentid As String) As String
	Dim sFileName As String = Nothing
	sFileName = ""
	Using conn1 As New SqlConnection(connString)
		Using cmd1 As New SqlCommand("SELECT handle FROM content c INNER JOIN AssetDataTable adt ON adt.id=c.asset_id WHERE content_id=" & contentid & ";", conn1)
			conn1.Open()
			Dim rdr1 As SqlDataReader = cmd1.ExecuteReader()
			If rdr1.HasRows Then
				While rdr1.Read()
					sFileName = rdr1("handle").ToString()
				End While
			End If
		End Using
	End Using
	Return sFileName
End Function
#End Region

#Region "Get file extension data from SQL - Start"
Public Function sGetFileExtension(ByVal contentid As String) As String
	Dim sFileExtension As String = Nothing
	sFileExtension = ""
	Using conn1 As New SqlConnection(connString)
		Using cmd1 As New SqlCommand("SELECT(CASE WHEN handle LIKE'%.%'THEN reverse(left(reverse(handle),charindex('.',reverse(handle))-1))ELSE''END)AS FilePath FROM content c INNER JOIN AssetDataTable adt ON adt.id=c.asset_id WHERE content_id=" & contentid & ";", conn1)
			conn1.Open()
			Dim rdr1 As SqlDataReader = cmd1.ExecuteReader()
			If rdr1.HasRows Then
				While rdr1.Read()
					sFileExtension = rdr1("FilePath").ToString()
				End While
			End If
		End Using
	End Using
	Return sFileExtension
End Function
#End Region
#End Region

#Region "Require visitor to login - Start"
Public Shared Function LoggedIn() As String
	Dim sLoggedIn As String = "no"
	Dim contentApi As New Ektron.Cms.ContentAPI()
	If contentApi.IsLoggedIn AndAlso contentApi.LoadPermissions(0, "users", Ektron.Cms.ContentAPI.PermissionResultType.All).IsLoggedIn Then
		sLoggedIn = "yes"
		'Allow access
		sUserID = contentApi.UserId.ToString()
	End If
	Return sLoggedIn
End Function
#End Region

#Region "Check User Group - Start"
Public Shared Function GetUserGroup(ByVal userID As Integer, ByVal GroupID As String) As Integer
	Dim inGroup As Integer = 0
	If userID <> 0 Then
		Dim query1 As String = "SELECT user_to_group_tbl.usergroup_id " & ",usergroups.usergroup_name " & ",user_to_group_tbl.user_id " & "FROM user_to_group_tbl " & "INNER JOIN usergroups ON user_to_group_tbl.usergroup_id = usergroups.usergroup_id " & "WHERE user_to_group_tbl.user_id = '" & userID & "'"

		Dim conn1 As New SqlConnection(connString)
		Dim cmd1 As New SqlCommand(query1, conn1)
		conn1.Open()
		Dim rdr1 As SqlDataReader = cmd1.ExecuteReader()
		If rdr1.HasRows Then
			While rdr1.Read()
				If rdr1("usergroup_id").ToString() = GroupID Then
					inGroup = 1
				End If

				If rdr1("usergroup_id").ToString() = "1" Then
					inGroup = 1
				End If
			End While
		End If
	End If
	Return inGroup
End Function
#End Region

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
	If LoggedIn() = "yes" AndAlso GetUserGroup(Integer.Parse(sUserID), "1") = 1 Then
		btnGenerate.Visible = True
	End If
End Sub

Protected Sub btnGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
		''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
		'Uses format provided here:
		'Framework API
		Dim api As New Ektron.Cms.Framework.Core.Content.Content
		Dim criteria As New Ektron.Cms.Common.Criteria(Of Ektron.Cms.Common.ContentProperty)
		Dim cf As New Ektron.Cms.Common.CriteriaFilter(Of Ektron.Cms.Common.ContentProperty)
		Dim cdatas As New System.Collections.Generic.List(Of Ektron.Cms.ContentData)
		Dim cdata As New Ektron.Cms.ContentData
		Dim pageInfo As New Ektron.Cms.PagingInfo

		'Set criteria filter to grab all content
		cf.Field = Ektron.Cms.Common.ContentProperty.Id
		cf.Operator = Ektron.Cms.Common.CriteriaFilterOperator.GreaterThan
		cf.Value = 0

		'Set limit for API
		'default 100k
		pageInfo.RecordsPerPage = 100000
		criteria.PagingInfo = pageInfo

		'Get Content for Sitemap
		criteria.Filters.Add(cf)
		cdatas = api.GetList(criteria)

		'create XML document
		Dim writer As New XmlTextWriter(Request.PhysicalApplicationPath.ToString + "sitemapsitemap-" + DateTime.Now.ToString("yyyy-MM-dd_HHmm") + ".xml", Encoding.UTF8)
		writer.WriteStartDocument()
		writer.WriteStartElement("urlset", "xmlns=http://www.sitemaps.org/schemas/sitemap/0.9")

		Dim tempDate As New Date

		'loop through each item, write to XML
		For Each cdata In cdatas

			writer.WriteStartElement("url")
			writer.WriteElementString("name", cdata.Title)
			writer.WriteElementString("loc", "http://" + Request.Url.Host.ToString + cdata.Quicklink.ToString)
			writer.WriteElementString("folder", cdata.Path)
			writer.WriteElementString("editor", cdata.EditorFirstName + " " + cdata.EditorLastName)
			writer.WriteElementString("contenttype", cdata.ContType)
			writer.WriteElementString("filename", sGetFileName(cdata.Id))
			writer.WriteElementString("fileextension", sGetFileExtension(cdata.Id))
			writer.WriteElementString("created", cdata.DateCreated)
			writer.WriteElementString("lastmod", cdata.DateModified)


			'Content modified in the last 7 days has a higher priority
			'can be configured to modify priority
			'If cdata.DateModified > Date.Now.AddDays(-7) Then

			'	writer.WriteElementString("priority", "1.0")

			'Else

			'	writer.WriteElementString("priority", "0.5")

			'End If

			writer.WriteEndElement()

		Next

		'Stop writing XML
		writer.WriteEndElement()
		writer.WriteEndDocument()

		writer.Close()

		'write out total items added to map
		results.InnerHtml = "Sitemap Created: " + cdatas.Count.ToString + " Items Added"
	End Sub
End Class

Based Off of Ektron Code Library – http://developer.ektron.com/Templates/CodeLibraryDetail.aspx?id=4294967329&blogid=116

Originally Posted on October 17, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Ektron VB.NET VB.NET ASPX

Post navigation

Previous post
Next post

Related Posts

PowerShell – Windows 7 – Windows Service Cleanup

Posted on November 9, 2015

There are many services on Windows 7 that do not need to run, while some suggest disabling the service I tend to go on the side of caution and simply stop and set them to manual startup. # Stop Services and set to Manual # Home Group Sharing – start…

Read More

PowerShell / Chocolatey Install WAMP

Posted on October 20, 2015October 20, 2015

Following the Chocolatey post we now install WAMP (Windows, Apache, MySQL, and PHP). Open PowerShell as administrator choco install -y wamp-server Configure WAMP for port 8080 copy "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf" "C:\wamp\bin\apache\apache2.4.9\conf\httpd_backup.conf" (gc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf").replace(‘Listen 0.0.0.0:80′,’Listen 0.0.0.0:8080’) | sc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf" (gc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf").replace(‘Listen [::0]:80′,’Listen [::0]:8080’) | sc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf" (gc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf").replace(‘ServerName localhost:80′,’ServerName localhost:8080’) | sc "C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf"…

Read More

Acrylic Proxy DNS Setup

Posted on October 16, 2015October 16, 2015

While still configuring my changes to Raspberry Pi Setup Proxy Server this works on an individual computer. NOTE: I have this setup mainly for the Wi-Fi, if you want it for wired connections you will need to change Wi-Fi to “Ethernet” or “Ethernet 2” Step 1: Download and Setup Acrylic…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes