So I decided I'd quickly throw together a Sharepoint EventReceiver to do the trick. I override the ItemAdded (Needs to be done on the ItemAdded method as item isn't considered to be created yet so can't be added as a valid link from the ItemAdding method) method of the SPItemEventReceiver.
All you need to do is Add this EventReceiver to the Wiki Pages Document Library. This means everytime a Wiki Page gets Added to the Wiki Pages Document Library it will add the URL of that Wiki Page to the Quick Launch Menu (Under Wiki Pages).
Code Below
namespace MRWA.Wiki.FeatureReceivers
{
class AddPageToNavigationEventReceiver : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem Item = properties.ListItem;
SPWeb Web = properties.ListItem.Web;
foreach (SPNavigationNode WikiPagesNode in Web.Navigation.QuickLaunch)
{
if (WikiPagesNode.Title == "Wiki Pages")
{
string ItemUrl = Web.ServerRelativeUrl + "/Wiki Pages/" + Item["FileLeafRef"].ToString();
string ItemName = Item["FileLeafRef"].ToString().Replace(".aspx", "");
bool CreateNavNode = true;
foreach (SPNavigationNode ChildNode in WikiPagesNode.Children)
{
if (ChildNode.Title == ItemName && ChildNode.Url == ItemUrl)
{
CreateNavNode = false;
break;
}
}
if (CreateNavNode)
{
SPNavigationNode NavNode = new SPNavigationNode(ItemName, ItemUrl);
WikiPagesNode.Children.AddAsLast(NavNode);
}
break;
}
}
base.ItemAdding(properties);
}
}
}
No comments:
Post a Comment