Programmatically Show\Hide or Change links in quick launch bar |
You can programmatically Show\Hide or Change Url for the links in Quick Launch bar according to the logged in User or Whatever your condition is. In this post however, we will just Change the Url for one of links in quick launch bar, according to the logged in user's group. The Code is written in a User Control which will later be added to the master page. Adding the Control in the master page does add some overhead but will allow the code to run on each sharepoint page. Initial requirement - Change the Url for one of the links called "Your Department" in quick launch bar according to the logged in user's group. Steps : 1. Create Webapplication project and add a Web UserControl in it. 2. Add References to Microsoft.SharePoint dll. Use the below method in Page load to Change the url: private void ChangeLink(string NewLink) { SPSite site = SPContext.Current.Site; SPWeb myWeb = site.RootWeb; SPSecurity. { using (SPSite siteCollection = new SPSite(site.ID)) { using (SPWeb web = siteCollection.OpenWeb(myWeb. { web.AllowUnsafeUpdates = true; SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch; foreach (SPNavigationNode node in nodes) { CheckURL(node,web, NewURl); } web.AllowUnsafeUpdates = false; } } }); } private void CheckURL(SPNavigationNode Node,SPWeb web,string NewURl) { if (Node.Children.Count > 0) { SPNavigationNodeCollection childNodes = Node.Children; foreach (SPNavigationNode cNode in childNodes) { if (cNode.Title.ToString() == "Your Department") { cNode.Url = NewURl; cNode.Update(); } } } } In above Code CheckURL method will navigate through each link in the quick launch bar to find the one with name "Your Department". If the link is found we can simply use cNode.Url and cNode.Update() to update the url. 3. After, you are done writing the logic, just Sign the Project and Build it. Dont forget to drop the signed dll in GAC. 4.. Finally, add the user Control in the Master Page and Test it. |
Programatically get the enforce relationship behavior for lookup field Sharepoint 2010 |
|
Programatically get the enforce relationship behavior for lookup field Sharepoint 2010 |
The code below helps to check weather the field in your current list is a Lookup field to someother list and determine its enforce relationship behavior. To do this we will use a console application and will use GetRelatedFields() on parent list which will Return a collection of objects with information about a lookup field in another list that points to a field in this list. Code : using (SPSite site = new SPSite(“http://SPsite”)) |
Monday, November 28, 2011
Programmatically Show\Hide or Change links in quick launch bar
Category:
SharePoint 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment