We can access the quick launch from the "navigation" object available in "web" object.
web.Navigation.QuickLaunchThe QuickLaunch object is of type SPNavgationNodeCollection wich contains the collection of SPNavigationNode. There is a built in method "Update" provided in SPNavigationNode class to save any changes made in SpNavigationObject properties to the database. I tried to use the method after updating the URL of QuickLaunch link
SPNavigationNode Node = web.Navigation.QuickLaunch[Counter];But it didn't work for me. I googled this issue a lot but no luck :(. After a lot of thinking on this issue and exploring the Update method using reflector I came to know that update method actually calls UpdateNavigationNode() that resides inside SPRequest object.
Node.Url = "NewURL/Confirmation.aspx";
Node.Update();
this.Navigation.Web.Request.UpdateNavigationNode(this.Navigation.Web.Url, this.Id, this.m_dtParented, this.Title, this.Url, ref this.m_PropertyArray, out str)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmecNpRE8AIIMb3AKl7QdKVbY092mOQyjUzkfSdOowsZ2Tye6eyLLLOW4Jfbo5ua6T6umra8u76Ew7ZySzxh4l4xUMAG4AkZtkb5e_g8fE-FeoKyRwbLX4bIo6V1JmrSu9fwpT4-I-axKd/s320/Update+Method.bmp)
Unfortunately SPRequest object is marked with "internal" access modifier and we can not access it from another assembly. but i have to call it directly to update the content database with my URL change so I decided to use reflection to access the internal object
Object Request = null;After successfully getting the Request object I also need to execute the UpdateNavigationNode() method using reflection because it is also marked with "internal" access modifier
Request=web.GetType().GetField("m_Request",System.Reflection.BindingFlags.NonPublic |System.Reflection.BindingFlags.Instance).GetValue(web);
Request.GetType().GetMethod("UpdateNavigationNode").Invoke(Request, new Object[] { node.Navigation.Web.Url, node.Id, node.LastModified, node.Title, URL, (m_PropertyArray), str });Finally the method looks like this
void UpdateQuickLaunchNodeURL(SPWeb web, SPNavigationNode node, string URL)And this code worked for definitely. Hope it will help others.
{
Object Request = null;
Request = web.GetType().GetField("m_Request", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(web);
object m_PropertyArray = new object();
string str = "";
Request.GetType().GetMethod("UpdateNavigationNode").Invoke(Request, new Object[] { node.Navigation.Web.Url, node.Id, node.LastModified, node.Title, URL, (m_PropertyArray), str });
web.Update();
}
Waah bhai waah. Good hai.. :) Shabash Asad.
ReplyDeleteThanks salman bhai, First comment to any of my post :D
ReplyDelete