CustomAction Link on Subsite Redirects to Parent Site—SharePoint 2007

I recently had a problem where a Custom Action link that we had added to a SharePoint subsite’s “Create” page was pointing to the relative URL of the parent site.  I discovered that it was because, without a “scope identifier” on the UrlAction element of the CustomAction, the relative URL will default to the root site of a site collection.  So, to fix the problem I added “~site” to the beginning of the URL as you can see here:

<CustomAction Id="CreateCustomPage" GroupId="WebPages"
     Location="Microsoft.SharePoint.Create" Sequence="400"
     Title="Page from Template" Description="Creates a branded page."
    
RequireSiteAdministrator="True"
     I
mageUrl="/_layouts/images/ltblnkpg.gif" >

 <UrlAction Url="~site/_layouts/CustomDirectory/CustomPage.aspx"/>

</CustomAction>

Without including the “~site” statement this will, apparently, default to the root of the site collection, which means your subsites will redirect back to the root site without it.  After adding this everything worked fine.  All of my subsites go to the proper relative URL of their own.

Andre Vala has a great blog post that discusses SharePoint Custom Actions in greater detail.  This blog also explains the other items that you can place at the beginning of the UrlAction’s URL besides ~site (i.e. ~sitecollection and others), and it helped me to figure this problem out fairly quickly.

Technorati Tags: ,,,,,,,,,

Windows Live Tags: WSS,MOSS,CustomAction,Subsite,Parent,SharePoint,Custom,Action,UrlAction,Microsoft

Leave a comment

Leave a comment