Tuesday, July 1, 2008

Adding Links to QuickLaunchBar....


Sample Lists.xml

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//Begin--Adding a Link to QuickLaunchBar....
ABCConfig config = new ABCConfig();
SPWeb site = (SPWeb)properties.Feature.Parent;
SPWeb rootsite = site.Site.RootWeb;
SPNavigationNodeCollection navColl = site.Navigation.QuickLaunch;
SPNavigationNode navNode = new SPNavigationNode("Submissions", "");
navColl.AddAsFirst(navNode);

//Read name and urls from the xml file
XmlDocument doc = new XmlDocument();

string ListOperationXMLPath = config.GetConfigValue(rootsite, "ABCLinks");
doc.Load(ListOperationXMLPath);
XmlNodeList lists = doc.GetElementsByTagName("Link");
foreach (XmlNode node1 in lists)
{
XmlElement fieldElement = (XmlElement)node1;
string FieldNameTitle = "";
string xmlUrl = "";
string siteUrl = "";
if (fieldElement.HasAttributes)
{
FieldNameTitle = fieldElement.Attributes["Title"].InnerText;
xmlUrl = fieldElement.Attributes["Url"].InnerText;
siteUrl = "/" + site.Title + "/"+xmlUrl;
SPNavigationNode node = new SPNavigationNode(FieldNameTitle, siteUrl);
foreach (SPNavigationNode nodes in site.Navigation.QuickLaunch)
{
if (nodes.Title.Equals("Submissions", StringComparison.InvariantCultureIgnoreCase))
{
nodes.Children.AddAsLast(node);
break;
}
}
}
}

No comments: