Sitemap Macro

I wrote a Visual Studio macro to walk an ASP.NET 2.0 project and create a web.sitemap based on the physical layout of files.

Download.

The macro requires a reference to System.Xml.dll. The macro won’t overwrite or synchronize an existing web.sitemap file, it’s only meant to save some typing if you have an existing project and want to add a sitemap. Once the macro creates the sitemap, you can go in and modify the titles, descriptions, and layout.

Update: Fixed the macro to work with IIS based projects, and added Dan Kahler's suggestion to prompt user to overwrite existing file.

posted on Tuesday, November 29, 2005 11:46 PM by scott

Comments

Wednesday, November 30, 2005 12:21 AM by Keyvan Nayyeri

# re: Sitemap Macro

Well done;
But a question. As you wrote here:
Private ReadOnly validSiteMapNodes() As String = {".ASPX", ".HTML", ".HTM"}
By default it tries to find all pages and add them to SiteMap file but if someone tries to add pages based on Queries he will be unsuccessful.
So probably each developer needs to write same Macro based on his Queries to generate his own SiteMap file? In most cased we have just one .ASPX page but handle many pages on it ;)
And another question: Why it's necessary to have a default start page for project to generate its SiteMap node? Maybe I try set my /Weblog/default.aspx page as default but my home page is /default.aspx file. Which file will be defined as my Home Page in SiteMap file?
Wednesday, November 30, 2005 5:31 AM by scott

# re: Sitemap Macro

Hi Keyvan:

Good questions. As I said, the macro only builds a sitemap based on the physical layout. If you do any URL re-writing, virtual path provider trickery, or query string magic - it won't know about those URLs. At least it gives you a starting point to copy and paste additional siteMapNodes - I was just looking to avoid some typing.

As for the default start page - the site map has to have a root <siteMapNode> to represent the top of the navigation tree. For me, the best way to determine the root node was just to look at the start page property. It's not a requirement for sitemaps in general.
Wednesday, November 30, 2005 11:20 PM by Paul Litwin

# re: Sitemap Macro

I have been thinking that such a utility would be cool to create. And you beat me to it. Cool.

Okay at the risk of sounding like an idiot...I've never used VS macros before. How do I make use of your macro. I've been playing around with the VS Macros menus, IDE, explorer, etc. and am totally clueless. I want to use your macro but do not know what to do to use it.
Thanks,
Paul
Thursday, December 01, 2005 6:13 AM by scott

# re: Sitemap Macro

I fixed one little bug and uploaded a new version.

Paul, I should have left installation instructions:

1) Open macro explorer (Alt + F8)

2) Right click MyMacros, select New Module (the module name can be anything)

3) Right click the new module and select Edit

3) Replace the contents of the new module with the contents of SiteMapModule.vb

4) Right click References under MyMacros and add a reference to System.Xml

Hopefully that is enough to get you running. Now in the Macro Explorer window of VS.NET you can right click and run the macro...
Thursday, December 01, 2005 7:25 AM by scott

# re: Sitemap Macro

I learned something new -

In step 2 I said the module name can be anything.

Turns out, the name of the module must match the name of the Public Module definition inside.

In other words, I use

Public Module SiteMapModule
'''
End Module

So the module itself must be called SiteMapModule. You can right click the module in Macro Explorer and select "Rename" if it's not named properly..

Thursday, December 01, 2005 12:03 PM by Paul Litwin's Blog

# The Top 7 Things Microsoft Blew in VS 2005/ASP.NET 2.0

Okay, now that I have published a few top ten lists for the latest from Microsoft, it's time for a top...
Thursday, December 01, 2005 12:20 PM by Paul Litwin

# re: Sitemap Macro

That worked. Thanks!
Paul
Thursday, December 01, 2005 12:30 PM by Dan Kahler

# re: Sitemap Macro

Hey Scott, this is really handy - thanks! Works like a champ.

I've found a small modification that's useful to me:

Within the ProcesWebSite sub, I've modified the MsgBox line within "If HasSiteMap(...)" to ask if you'd like to overwrite the existing sitemap file (MsgBoxStyle.YesNo), and moved the Return statement inside this If block. This little tweak saves another step, especially if you're rapidly prototying page organization.

As always, EXCELLENT work.
Thursday, December 01, 2005 4:05 PM by scott

# re: Sitemap Macro

Dan: I really thought you should run with it some more and create something that keeps the sitemap in synch with an existing project ;)
Friday, December 02, 2005 6:11 AM by PuntoRete

# Una macro per generare il web.sitemap

Friday, December 02, 2005 12:22 PM by Kerric

# re: Sitemap Macro

I tried to install and run the macro in VS2005

I had a problem running the macro and got the following error

URI formats are not supported.

When debugging the code, i noticed that you use the path of the web project and append the name web.sitemap. In VS2005 the path of the webproject is a url in my case to the my localweb server. Im not familiar with the framework for VS Studio is there another property which can find the physical path of the project?
Friday, December 02, 2005 12:37 PM by scott

# re: Sitemap Macro

Hi Kerric:

I'll have to investigate that one. I've only used the macro with a file system based project, not one hosted in IIS. It might be an easy fix (just use a different project property).
Friday, December 02, 2005 1:25 PM by Dan Kahler's WebLog

# Web.Sitemap VS 2005 Macro

Friday, December 02, 2005 2:03 PM by Scott

# re: Sitemap Macro

Ok, updated file in place to work with IIS projects.
Friday, December 02, 2005 3:52 PM by Dan Kahler's WebLog

# Web.Sitemap VS 2005 Macro

Saturday, December 03, 2005 12:42 PM by Bill

# re: Sitemap Macro

Are you good at every area of .NET or what. Wayyy cool man!
Thursday, December 08, 2005 7:02 PM by Christopher Steen

# Link Listing - December 8, 2005

[tip] localhost vs. (local) in SQL Server connection
strings [Via: Jon
Galloway ]
ASP.NET 2.0 Upgrade...
Monday, January 02, 2006 8:03 AM by The Design-Time Developer

# I once was lost, but now I'm found (SiteMap tools now available)

A few months back, I spoke about the new features in ASP.NET 2.0, including the SiteMap feature to simplify...
Tuesday, January 03, 2006 12:07 AM by Radicalmente

# ASP.NET 2.0: Sitemap a go-go

Tuesday, January 03, 2006 12:09 AM by Di .NET e di altre amenita'

# ASP.NET 2.0: Sitemap a go-go

Thursday, January 12, 2006 2:34 PM by blog.dreampro

# Web.sitemap bits

Thursday, January 19, 2006 12:53 PM by Sara Ford's WebLog

# VS Macro to Build a Web.SiteMap file from your project system file layout

Today’s tip comes from Scott Allen’s blog.&amp;nbsp; Scott has provided a VS 2005 macro that will dynamically...
Thursday, January 19, 2006 6:06 PM by Another Day in the Antz Farm

# A Macro to Generate Web.Sitemap

During the recent Community Launch, Alan and Alvin introduced about the navigation features in ASP.NET...
Monday, January 23, 2006 5:17 AM by Yitzhak Gootvilig's Blog

# Sitemap Macro - from K. Scott Allen

Monday, January 23, 2006 5:18 AM by Yitzhak Gootvilig's Blog

# Sitemap Macro - from K. Scott Allen

Tuesday, January 24, 2006 6:05 AM by Neal

# re: Sitemap Macro

This is awesome. How would you generate the web.sitemap upon page load? In other words how could I accomplish this without the macro?
Tuesday, January 24, 2006 6:09 AM by scott

# re: Sitemap Macro

Neal:

You could use the same code that is in the macro to walk the filesystem and make a web.config file. I'd try to do this from Application_Start instead of a Page_Load.
Tuesday, January 24, 2006 8:15 AM by Neal

# re: Sitemap Macro

Could you plz give me an example?
Tuesday, January 24, 2006 6:49 PM by Scott

# re: Sitemap Macro

Actually Neal, after thinking about this, the proper way to generate a sitemap at runtime would be to write a custom provider. That's a little more than a simple example :)

There is a white paper on the topic here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNETProvMod_Prt3.asp
Thursday, February 02, 2006 5:49 PM by B³: Beto Borbolla Blog

# Macro para crear el Site Map Autom&amp;#225;ticamente

El Site Map es un feature bastante cool de ASP.NET 2.0, sin embargo implica que para mostrar el mapa...
Wednesday, February 22, 2006 9:08 AM by Sharbel

# re: Sitemap Macro

Hey Scott,

Nice Macro! I do have a little problem, it seems that the directories and filetypes listed in the validSiteMapNodes() and the excludeDirectoriesPrefix() are not being enforced correctly?

For example, in my /images directory, I have a bunch of .jpg/.gif/.png etc type files. An XML node is created for each one, however, no URL attribute is inserted, just a title. I would assume that the whole Node should be foregone?

Moreover, I edited the excludeDirectoriesPrefix() to include a few directories I didnt want crawled, but they still are crawled.

Are these known problems?
Wednesday, February 22, 2006 10:43 PM by scott

# re: Sitemap Macro

Sharbel:

I'm not aware of any problems - could it be a case sensitivity issue?
Thursday, March 23, 2006 6:59 AM by Robert J. Bullock

# re: Sitemap Macro

Dude, you just saved me 6-8 hours of annoying sitemap editing! THANK YOU!!!
Wednesday, March 29, 2006 8:53 AM by Sal

# re: Sitemap Macro

I 2nd the saving of time! Thanks!
Monday, April 10, 2006 11:39 AM by Joel Reinford

# A small modification

Scott:

This macro is a real time saver. I suggest making the file extension list and excludeddirectory list non-case sensitive by using .StartsWith(name.ToUpper) in each of the two methods below. You're already forcing the item name to uppercase so it just makes sense to force the search string to uppercase too.

Joel Reinford
Data Management Solutions LLC

Private Function IsValidDirectory(ByVal item As EnvDTE.ProjectItem) As Boolean

If item.ProjectItems Is Nothing Then
Return False
Else
For Each name As String In excludeDirectoriesPrefix
If item.Name.ToUpper().StartsWith(name.ToUpper) Then
Return False
End If
Next
End If

Return True

End Function

Private Function IsValidFile(ByVal item As EnvDTE.ProjectItem) As Boolean

For Each name As String In validSiteMapNodes
If item.Name.ToUpper().EndsWith(name.ToUpper) Then
Return True
End If
Next

Return False

End Function
Thursday, April 27, 2006 8:24 AM by Michell Cronberg

# Microsoft-foredrag i Vedb&#230;k (ASP3 til ASP.NET2)

Monday, May 01, 2006 9:03 PM by ben

# re: Sitemap Macro

error in code:

Dim dte1 As New EnvDTE.DTE
'For Each project As EnvDTE.Project In DTE.Solution.Projects
For Each project As EnvDTE.Project In dte1.Solution.Projects

Monday, May 01, 2006 9:13 PM by scott

# re: Sitemap Macro

Ben: You shouldn't need that code. You'll want a reference to the existing DTE, not a new one. What problem were you having?
Thursday, June 29, 2006 10:32 AM by Joseph Leonard

# re: Sitemap Macro

Can't get this to work. VS 2005 says following:
Private siteMap As XmlDocument Error "XmlDocument" not definded.

Also pressing F5 does nothing. No error messages and macro does not run.

Is there a walk-through on setting this up?
Thursday, June 29, 2006 10:35 AM by John Roberts

# Sitemap Macro instructions?

Instructions not correct for VS 2005:
I fixed one little bug and uploaded a new version.

4) Right click References under MyMacros and add a reference to System.Xml (There is no such choice after right clicking here. Unable to continue with setup.)

Also how does one RUN the macro?
Monday, July 03, 2006 2:52 PM by Darin

# re: Sitemap Macro

Any chance that this would work in Visual Studio 2003?
Monday, July 03, 2006 8:52 PM by scott

# re: Sitemap Macro

Darin:

The macro itself might work in 2003 (I have not tried it), but the sitemap features are 2.0 only, so it may not be useful.
Tuesday, August 01, 2006 2:33 AM by 骑人的驴

# Scott Mitchell 的ASP.NET 2.0数据操作教程之九:跨页面的主/从报表

ASP.NET2.0中的数据操作::跨页面的主/从报表 英文原版|代码|英文PDF版 导言 在前面的两篇教程中,我们看到了如何在单一页面中显示主/从报表,它使用DropDownL...
Thursday, August 17, 2006 5:13 AM by 冷火

# Scott Mitchell 的ASP.NET 2.0数据操作教程之九:跨页面的主/从报表

导言 在前面的两篇教程中,我们看到了如何在单一页面中显示主/从报表,它使用DropDownList显示主记录,使用GridView或DetailsView显示详细信息.另外一种常见的主/从报表模...
Friday, October 13, 2006 9:41 PM by Sean Loughrey

# re: Sitemap Macro

This is a great utility. One thing I found is that this will not work if using the web application project add-in. I kept getting a '0' web-site processed message. To test this I created and empty web project and added my file and it worked perfectly. I think I need to change the webProjectKind As String = "{E24C65DC-7377-472B-9ABA-BC803B73C61A}" reference. Can anyone tell where to find the reference for this. Scott. Good work as always.
Sunday, October 15, 2006 8:21 PM by scott

# re: Sitemap Macro

Sean:

For now, you might just remove the code that checks for the project type. I'll try to get out an update that works with WAP this week.
Tuesday, October 17, 2006 3:45 PM by Community Blogs

# SiteMap Macro v2.0

Last year I wrote a little macro to generate a web.sitemap file for ASP.NET 2.0. A few people have been
Monday, October 23, 2006 1:14 PM by Tatyana

# re: Sitemap Macro

how does one RUN the macro? I do not see the option to run if right click on macro ...
Wednesday, November 08, 2006 8:23 AM by Keith

# re: Sitemap Macro

Tatyana: I noticed that Scott hasn't replied to your question yet, so I will help him out:

If you name the macro SiteMapModule (you have to name the module the same as the module name in the code), in your Macro Explorer, it will show the CreateWebStemap method under the macro. (If it doesn't, you don't have the module's name set correctly.) You can then right-click on the method (in this case, there is only one: CreateWebSitemap) and get the Run menu option.

HTH
Monday, December 18, 2006 10:54 AM by Yitzhak Gootvilig's Blog

# Sitemap Macro - from K. Scott Allen

Friday, March 02, 2007 11:35 AM by Chris Love's Official Blog - Professional ASP.NET

# SiteMap Provider Links

I am doing a presentation on Custom SiteMap Providers tomorrow for the Roanoke Valley Code Camp. I thought
Sunday, April 01, 2007 11:20 PM by wanghr74

# Scott Mitchell 的ASP.NET 2.0数据操作教程之九:跨页面的主/从报表

在浏览器中访问一下SupplierListMaster.aspx. 如图7所示, 页面列出了所有的供应商,每个供应商包含”查看产品”链接. 单击”查看产品”链接会转到ProductsForSupplierDetails.aspx, 并在查询字符串中传递供应商的SupplierID值.图 7: 每个供应商都包含”查看产品”链接. Step 3: 在ProductsForSupplierDetails.aspx上列出供应商的产品。
Tuesday, September 18, 2007 1:19 AM by 拝啓、さかもとと申します

# Master/Detail Filtering Across Two Pages

ASP.NET DataAccess Tutorial #9 さかもとの自習シリーズ。 1つのページでクリックして、その情報を元に2つ目のページで詳細を表示してみましょう。詳細情報が無かったら「無いよ。ばーか」というメッセージを表示。
Tuesday, September 18, 2007 1:19 AM by 拝啓、さかもとと申します。

# Master/Detail Filtering Across Two Pages

Master/Detail Filtering Across Two Pages
Monday, February 25, 2008 4:36 PM by srock

# 用宏自动生成Web.sitemap文件(ASP.NET 2.0)

运行这个宏会遍历整个工程,更具目录结构生成Web.sitemap文件。这个宏不会覆盖原有的Web.sitemap文件,只是在你想新建一个Web.sitemap文件的时候,帮你生成一个模板。
Wednesday, March 12, 2008 1:55 AM by huojia0908

# ASP.NET 2.0中的数据操作 :: 跨页面的主/从报表

ASP.NET 2.0中的数据操作 :: 跨页面的主/从报表
Wednesday, March 12, 2008 1:55 AM by huojia0908

# ASP.NET 2.0中的数据操作 :: 跨页面的主/从报表

ASP.NET 2.0中的数据操作 :: 跨页面的主/从报表
Sunday, May 11, 2008 2:01 PM by <%= John Rummell %>

# A SiteMapProvider for Static Web Sites

A SiteMapProvider for Static Web Sites
Wednesday, July 02, 2008 2:02 PM by <%= John Rummell %>

# A SiteMapProvider for Static Web Sites

A SiteMapProvider for Static Web Sites
Wednesday, July 02, 2008 2:04 PM by <%= John Rummell %>

# A SiteMapProvider for Static Web Sites

A SiteMapProvider for Static Web Sites