Click here to Skip to main content
14,638,374 members
Articles » Languages » VB.NET » Utilities
Posted 10 Jan 2006


16 bookmarked

Making Google XML SiteMaps From Files

Rate this:
3.86 (3 votes)
Please Sign up or sign in to vote.
3.86 (3 votes)
10 Jan 2006
An application to make Google XML sitemaps from file structures.


This application can make XML files for the Google sitemap. You need to only get the path of your web site and the URL of the site, and then save the XML file where you want.

How it Works

At the Path tab, you give the address of the main directory of your web and the URL of your website.

At the Extension tab, you must configure what kind of files your project will contain. The application has to know the type of extensions that must be listed in the XML file.

Then in the File tab, after clicking "Read from directory", the program will start to search the directory for file extensions you configured in the Extension tab. The program will ignore the directories that starting with '_' in their names, because they are private directories and the browser can't show them. The application gets the file path and the last write time of the file, and leave other settings unchecked.

Because some pages can have query information, you must check the "This page has query" option.

In the Query tab, you must configure the queries for the pages, and then at the Save tab, save the XML file.

How the Code Works

We have a class "siteMap" that contains the information for the pages. This class can make the part of the XML file that is related to this file; this means all the files with the GetXML method returns a part of the XML file. All of this will be merged together to make the main XML file. This is the GetXML method:

Public ReadOnly Property GetXML() As String
        Dim Str As String
        Str = "<url>" & vbCrLf
        Str &= "<loc>" & URL & Loc & "</loc>"
        Loc = EscapeCode(Loc)
        If CheckLastMod = True Then
            Dim ModStr As String = LastMod.Date.ToShortDateString
            ModStr = ModStr.Replace("/", "-")
            Str &= vbCrLf & "<lastmod>" & ModStr
            If CheckLMTime = True Then
                Str &= "T" & GetTime() & "+00:00"
            End If
            Str &= "</lastmod>"
        End If
        If CheckChangeFreq = True Then
            Str &= vbCrLf
            Str &= "<changefreq>" & ChangeFreq.ToString() & "</changefreq>"
        End If
        If CheckPriority = True Then
            Str &= vbCrLf
            Str &= "<priority>" & Priority & "</priority>"
        End If
        Str &= vbCrLf & "</url>"
        Return Str
    End Get
End Property

The AddRootFiles function adds the files to the list box:

Private Sub AddRootFiles(ByVal Path As String)
    'Main Directory of files
    Dim Dir As DirectoryInfo
        Dir = New DirectoryInfo(Path)
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Local directory error", 
                MessageBoxButtons.OK, MessageBoxIcon.Error)
        Exit Sub
    End Try

    If Dir.Exists = False Then
        MessageBox.Show("The local directory path" & _ 
                        " not exist. please choose" & _ 
                        " address for local directory" & _ 
                        " on Path tab.", _
                        "local directory not exist", _
                        MessageBoxButtons.OK, _
        Exit Sub
    End If

    Dim File As FileInfo
    Dim Ext As String
    If txtLocalPath.Text.Chars(txtLocalPath.Text.Length_
                                       - 1) <> "\" Then
        txtLocalPath.Text &= "\"
    End If
    For Each File In Dir.GetFiles
        For Each Ext In lsbExtension.Items
            If ("." & Ext).ToLower = _
                      File.Extension.ToLower Then
                If lsbFiles.Items.IndexOf("/" & _
                            File.Name) = -1 Then
                    Dim str As String = _
                       File.FullName.Replace(txtLocalPath.Text, "/")
                    Dim NewMap As New SiteMap
                    NewMap.CheckChangeFreq = False
                    NewMap.CheckLastMod = True
                    NewMap.CheckLMTime = True
                    NewMap.CheckPriority = False
                    NewMap.CanShowWithoutQ = True
                    NewMap.LastMod = File.LastWriteTime()

                    NewMap.Loc = str.Replace("\", "/")
                End If
            End If
    Dim SDir As DirectoryInfo
    For Each SDir In Dir.GetDirectories
        If Not SDir.Name.StartsWith("_") Then
        End If

End Sub


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Hamed J.I
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
I began programming with C/C++ when i was 15. Then try to learn VC++ but at the middle of my reading .NET came.

I began to read C# and VB.NET and also began designing basic websites by FrontPage and developed some websites for our school and some other companis.

Later learn Microcontroller and design some digital circuits with PIC microcontrollers for a industrial controller company.

As I learned SQL and ASP.NET developed some website such as news portals that are active now.

Now i'm a software student and teach programming in computer institues. And have my own job by getting projects from companies.

Comments and Discussions

-- There are no messages in this forum --