Monday, May 27, 2013
Fetch the list of all the sitecollection and subsites under the webapplication and create a sharepoint menu
public class _starter : MasterPage
{
protected Menu CustomMenu;
protected void Page_Load(object sender, EventArgs e)
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
SPWebApplication webapp = site.WebApplication;
CustomMenu.Items.Clear();
BeginProcess(webapp);
}
}
public void BeginProcess(SPWebApplication webApp)
{
//Execute any logic you need to against the web application
//Iterate through each site collection
foreach (SPSite site in webApp.Sites)
{
using (SPWeb oSPWeb = site.OpenWeb())
{
MenuItem parentMenuItem = new MenuItem(oSPWeb.Title, oSPWeb.Title, "", oSPWeb.Url);
CustomMenu.Items.Add(parentMenuItem);
if (oSPWeb.Webs.Count > 0)
{
RecursiveWebCheck(oSPWeb, parentMenuItem);
}
}
}
}
private void RecursiveWebCheck(SPWeb parentoSPWeb, MenuItem parentMenuItem)
{
foreach (SPWeb web in parentoSPWeb.Webs)
{
//web.Dispose();
//if (parentoSPWeb.Webs.Count > 0)
//{
MenuItem childMenuItem = new MenuItem(web.Title, web.Title, "", web.Url);
parentMenuItem.ChildItems.Add(childMenuItem);
RecursiveWebCheck(web, childMenuItem);
//}
web.Dispose();
}
}
}
Monday, May 20, 2013
Set Master page when new sub site is created
Step 1:
Create Master page using following URL
http://msdn.microsoft.com/en-us/library/gg447066.aspx
Step 2:
Create Event receiver(right click -> Add New Item-> Event Receiver)
Step 3:
Choose Web events as Event Receiver type
and select "A Site was provisioned"
Create Master page using following URL
http://msdn.microsoft.com/en-us/library/gg447066.aspx
Step 2:
Create Event receiver(right click -> Add New Item-> Event Receiver)
Step 3:
Choose Web events as Event Receiver type
and select "A Site was provisioned"
Step 4:
public override void WebProvisioned(SPWebEventProperties properties)
{
SPWeb topLevelSite = properties.Web;
string WebAppRelativePath = topLevelSite.Url;
if (!WebAppRelativePath.EndsWith("/"))
{
WebAppRelativePath += "/";
}
topLevelSite.MasterUrl = WebAppRelativePath +
"_catalogs/masterpage/Muthuvel2SpCustomMaster.master";
topLevelSite.CustomMasterUrl = WebAppRelativePath +
"_catalogs/masterpage/Muthuvel2SpCustomMaster.master";
topLevelSite.UIVersion = 4;
topLevelSite.Update();
}
Step 5:
Deploy the application.
Step 6:
Go the the application and create new site. The master page applied for the newly created site.
REF URL: http://www.sharepointkings.com/2012/04/implement-sharepoint-2010-site-event.html
REF URL: http://www.sharepointkings.com/2012/04/implement-sharepoint-2010-site-event.html
Thursday, May 16, 2013
Monday, May 13, 2013
Sharepoint mega menu
Sample URL: http://www.ramto.com/blog/post/Mega-Dropdown-Menu-with-ASPNET-and-jQuery-in-C.aspx.
UI:
Add CSS and JS
<link href="/_layouts/Muthuvel2SP/CSS/jkmegamenu.css" type="text/css" rel="stylesheet" />
<script src="/_layouts/Muthuvel2SP/JS/jkmegamenu.js" type="text/javascript"></script>
Add 2 literal Control
<asp:Literal ID="anchorLiteral" runat="server"></asp:Literal>
<asp:Literal ID="menuLiteral" runat="server"></asp:Literal>
Add OnDataBound="Menu1_DataBound" event in the menu control
Master Page Code behind File:
protected void Menu1_DataBound(object sender, EventArgs e)
{
//hide the asp menu
demoGlobalNavAspMenu.Visible = false;
//holds html anchors
anchorLiteral.Text = "";
//holds html mega dropdown menu
menuLiteral.Text = "";
//register megamenu script and create anchor foreach top level
StringBuilder mScript = new StringBuilder();
StringBuilder anchorText = new StringBuilder();
StringBuilder menuText = new StringBuilder();
mScript.AppendLine(@"<script type='text/javascript'>");
int cntLvl1 = 0;
foreach (MenuItem lvl1 in demoGlobalNavAspMenu.Items)
{
cntLvl1++;
string anchorId = "megaanchor" + cntLvl1.ToString();
string megamenuId = "megamenu" + cntLvl1.ToString();
//anchor for each top level menu
anchorText.AppendLine("<a href='" + lvl1.NavigateUrl + "' id='" +
anchorId + "' class='topMenuCMSListMenuLinkHighlighted'>" +
lvl1.Text + "</a>");
//building mega menu div if menuitem has children
if (lvl1.ChildItems.Count > 0)
{
int cntLvl2 = 0;
//script for each top level menu
mScript.Append(@"jkmegamenu.definemenu('" + anchorId + "', '" +
megamenuId + "', 'mouseover');");
menuText.AppendLine("<div id='" + megamenuId + "' class=megamenu>");
//building columns within the mega menu
foreach (MenuItem lvl2 in lvl1.ChildItems)
{
cntLvl2++;
menuText.AppendLine("<div class='column'>");
menuText.AppendLine("<h3><a href='" + lvl2.NavigateUrl + "'>" +
lvl2.Text + "</a></h3>");
//create ul list if any children
if (lvl2.ChildItems.Count > 0)
{
menuText.AppendLine("<ul>");
foreach (MenuItem lvl3 in lvl2.ChildItems)
{
menuText.AppendLine("<li><a href='" + lvl3.NavigateUrl + "'>" +
lvl3.Text + "</a></li>");
}
menuText.AppendLine("</ul>");
}
menuText.AppendLine("</div>");
//break after 2 columns
//if (cntLvl2 >= 2)
//{
// menuText.AppendLine("<br style='clear: left' />");
// cntLvl2 = 0;
//}
}
menuText.AppendLine("</div>");
}
}
anchorText.AppendLine("</ul>");
anchorLiteral.Text = anchorText.ToString();
menuLiteral.Text = menuText.ToString();
mScript.AppendLine(@"</script>");
Guid gid = System.Guid.NewGuid();
Page.ClientScript.RegisterStartupScript(this.GetType(), gid.ToString(), mScript.ToString());
}
UI:
Add CSS and JS
<link href="/_layouts/Muthuvel2SP/CSS/jkmegamenu.css" type="text/css" rel="stylesheet" />
<script src="/_layouts/Muthuvel2SP/JS/jkmegamenu.js" type="text/javascript"></script>
Add 2 literal Control
<asp:Literal ID="anchorLiteral" runat="server"></asp:Literal>
<asp:Literal ID="menuLiteral" runat="server"></asp:Literal>
Add OnDataBound="Menu1_DataBound" event in the menu control
Master Page Code behind File:
protected void Menu1_DataBound(object sender, EventArgs e)
{
//hide the asp menu
demoGlobalNavAspMenu.Visible = false;
//holds html anchors
anchorLiteral.Text = "";
//holds html mega dropdown menu
menuLiteral.Text = "";
//register megamenu script and create anchor foreach top level
StringBuilder mScript = new StringBuilder();
StringBuilder anchorText = new StringBuilder();
StringBuilder menuText = new StringBuilder();
mScript.AppendLine(@"<script type='text/javascript'>");
int cntLvl1 = 0;
foreach (MenuItem lvl1 in demoGlobalNavAspMenu.Items)
{
cntLvl1++;
string anchorId = "megaanchor" + cntLvl1.ToString();
string megamenuId = "megamenu" + cntLvl1.ToString();
//anchor for each top level menu
anchorText.AppendLine("<a href='" + lvl1.NavigateUrl + "' id='" +
anchorId + "' class='topMenuCMSListMenuLinkHighlighted'>" +
lvl1.Text + "</a>");
//building mega menu div if menuitem has children
if (lvl1.ChildItems.Count > 0)
{
int cntLvl2 = 0;
//script for each top level menu
mScript.Append(@"jkmegamenu.definemenu('" + anchorId + "', '" +
megamenuId + "', 'mouseover');");
menuText.AppendLine("<div id='" + megamenuId + "' class=megamenu>");
//building columns within the mega menu
foreach (MenuItem lvl2 in lvl1.ChildItems)
{
cntLvl2++;
menuText.AppendLine("<div class='column'>");
menuText.AppendLine("<h3><a href='" + lvl2.NavigateUrl + "'>" +
lvl2.Text + "</a></h3>");
//create ul list if any children
if (lvl2.ChildItems.Count > 0)
{
menuText.AppendLine("<ul>");
foreach (MenuItem lvl3 in lvl2.ChildItems)
{
menuText.AppendLine("<li><a href='" + lvl3.NavigateUrl + "'>" +
lvl3.Text + "</a></li>");
}
menuText.AppendLine("</ul>");
}
menuText.AppendLine("</div>");
//break after 2 columns
//if (cntLvl2 >= 2)
//{
// menuText.AppendLine("<br style='clear: left' />");
// cntLvl2 = 0;
//}
}
menuText.AppendLine("</div>");
}
}
anchorText.AppendLine("</ul>");
anchorLiteral.Text = anchorText.ToString();
menuLiteral.Text = menuText.ToString();
mScript.AppendLine(@"</script>");
Guid gid = System.Guid.NewGuid();
Page.ClientScript.RegisterStartupScript(this.GetType(), gid.ToString(), mScript.ToString());
}
Add JQUERY Accordion Panel in Quick Lunch
<script type="text/javascript">jQuery(function($) { $('.s4-ql li ul').hide(); $('.s4-ql ul li').hover(function() { $(this).find('a:first').next().slideToggle(); }, function() { $(this).find('a:first').next().slideToggle(); }).find('ul').each(function(index) { var $this = $(this); $this.parent().find('a:first .menu-item-text').append(['<span style=\'float:right;font-size:0.8em;\'>(', $this.children().length, ')</span>'].join('')); });});</script>
Subscribe to:
Comments (Atom)
