string link = System.Configuration.ConfigurationSettings.AppSettings["link"];
string HeaderlinkTitle = System.Configuration.ConfigurationSettings.AppSettings["HeaderLinkTitle"];
string SublinkTitle = System.Configuration.ConfigurationSettings.AppSettings["SubLinkTitle"];
string SitecollectionURL = System.Configuration.ConfigurationSettings.AppSettings["SitecollectionURL"];
using (SPSite site = new SPSite(SitecollectionURL))
{
SPWeb web = site.OpenWeb();
foreach (SPWeb subweb in site.AllWebs)
{
SPNavigationNodeCollection quickLaunchNodes = subweb.Navigation.QuickLaunch;
bool LinkisThere = false;
for (int i = 0; i <= quickLaunchNodes.Count-1; i++)
{
if (quickLaunchNodes[i].Title == HeaderlinkTitle)
{
LinkisThere = true;
int InitialChildrenCount = quickLaunchNodes[i].Children.Count;
bool ChildrenLinkisThere = false;
for (int j = 0; j < InitialChildrenCount; j++)
{
if (quickLaunchNodes[i].Children[j].Title == SublinkTitle)
{
ChildrenLinkisThere = true;
quickLaunchNodes[i].Children[j].Delete();
SPNavigationNode subMenuItem = new SPNavigationNode(SublinkTitle, link, true);
quickLaunchNodes[i].Children.AddAsFirst(subMenuItem);
break;
}
}
if (InitialChildrenCount == 0
ChildrenLinkisThere == false)
{
SPNavigationNode subMenuItem = new SPNavigationNode(SublinkTitle, link, true);
quickLaunchNodes[i].Children.AddAsFirst(subMenuItem);
}
break;
}
}
if (LinkisThere == false)
{
SPNavigationNode menuItem = new SPNavigationNode(HeaderlinkTitle, link, true);
quickLaunchNodes.AddAsLast(menuItem);
SPNavigationNode subMenuItem = new SPNavigationNode(SublinkTitle, link, true);
quickLaunchNodes[quickLaunchNodes.Count-1].Children.AddAsFirst(subMenuItem);
}
}
Console.WriteLine("Successfull");
Console.Read();
************************************************************************
APP.Config
No comments:
Post a Comment