mercredi 18 mars 2015

Add Page links programmatically to Sharepoint Quick Launch



I have a solution that deploys a web part with a web page, and I would like it to also add a Quick Launch home screen link to the created web page.


enter image description here


I tried a little code sniplet, that I added to my Feature Activation event listener, but it's not working.



SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSiteCollection = new SPSite("http://mySiteUrl"))
{
using (SPWeb oWeb = oSiteCollection.OpenWeb())
{
oWeb.AllowUnsafeUpdates = true;
// Create the node.
SPNavigationNodeCollection _quickLaunchNav = oWeb.Navigation.QuickLaunch;

SPNavigationNode _SPNode = new SPNavigationNode("Link Title", "http://link_url", true); //i tried with false, too. It didn't work

_quickLaunchNav.AddAsLast(_SPNode);
oWeb.Update(); //added this since I've seen it in some examples, but not every example had it
}
}
});


Am I missing something really basic in this? I even tried the method described here, but it was not doing anything: Best way to programmatically create/maintain SharePoint Quick Launch menu








0 commentaires:

Enregistrer un commentaire