locked
Adding navigation links through programming RRS feed

  • Question

  • Hi,

    We are building navigation links thrpough programming using AddNavigation node.

    Can you please let me know how to correct this? By the same code works in development & local environment. But on the production farm we are getting this issue.

    - Creating node for http:// abc.xyz.com/_layouts/viewlsts.aspx?BaseType=1

    2016-06-21 04:22:25,224 ERROR - Error occured in AddNavigationLink

    Microsoft.SharePoint.SPException: Cannot open "_layouts/viewlsts.aspx?BaseType=1": no such file or folder. ---> System.Runtime.InteropServices.COMException: <nativehr>0x81070215</nativehr><nativestack></nativestack>Cannot open "/ops/it/sm/sap/architecture/_layouts/viewlsts.aspx?BaseType=1": no such file or folder.

       at Microsoft.SharePoint.Library.SPRequestInternalClass.AddNavigationNode(String bstrUrl, String bstrName, String bstrNameResource, String bstrNodeUrl, Int32 lType, Int32 lParentId, Int32 lPreviousSiblingId, Boolean bAddToQuickLaunch, Boolean bAddToSearchNav, String& pbstrDateModified)

       at Microsoft.SharePoint.Library.SPRequest.AddNavigationNode(String bstrUrl, String bstrName, String bstrNameResource, String bstrNodeUrl, Int32 lType, Int32 lParentId, Int32 lPreviousSiblingId, Boolean bAddToQuickLaunch, Boolean bAddToSearchNav, String& pbstrDateModified)

       --- End of inner exception stack trace ---

       at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)

       at Microsoft.SharePoint.Library.SPRequest.AddNavigationNode(String bstrUrl, String bstrName, String bstrNameResource, String bstrNodeUrl, Int32 lType, Int32 lParentId, Int32 lPreviousSiblingId, Boolean bAddToQuickLaunch, Boolean bAddToSearchNav, String& pbstrDateModified)

       at Microsoft.SharePoint.Navigation.SPNavigationNode.AddInternal(Int32 iPreviousNodeId, Int32 iParentId, Boolean bAddToQuickLaunch, Boolean bAddToSearchNav)

       at Microsoft.SharePoint.Navigation.SPNavigationNodeCollection.AddInternal(SPNavigationNode node, Int32 iPreviousNodeId)

       at Infosys.SharePoint.Tools.SP2013Migration.ExecuteNavigationMapping.AddNavigationLink(SPNavigationNodeCollection currentNavNodes, XmlNode xnAnchor, SPWeb webObj, XmlDocument xdNavigation, Boolean& partialError) in

    Thursday, June 23, 2016 3:09 PM

Answers

  • Hi,

    Any update?

    Please check the code below:

    using (SPSite site = new SPSite("http://sp2013"))
    {
    	using (SPWeb web = site.OpenWeb())
    	{
    		SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;
    		SPNavigationNode node = new SPNavigationNode("SiteContents", "/_layouts/viewlsts.aspx?BaseType=1");
    		topnav.AddAsLast(node);
    	}
    }

    If the code still not works, please check your account permission.

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Patrick_Liang Friday, July 1, 2016 9:17 AM
    • Marked as answer by Patrick_Liang Tuesday, July 5, 2016 9:05 AM
    Tuesday, June 28, 2016 2:29 AM
  • Hi Patrick,

    Thanks for response. As mentioned before, we are using same code & user account using which we are executing this code is "system account".

    We could identify the issue. Basically, SPNavigationNode checks if the resource belongs to current web if we dont pass "External flag" to true. https://msdn.microsoft.com/en-us/library/ms415159.aspx Apparently, one of the above node, path was belonging to other web. So, by using this flag, we could resolve the issue.

    Thanks lot for your response.

    Regards,

    Manu


    Regards, Manu

    Thursday, July 7, 2016 8:30 PM

All replies

  • Hi,

    The following code snippet for your reference:

    using (SPSite site = new SPSite("http://sp2013"))
    {
    	using (SPWeb web = site.OpenWeb())
    	{
    		SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;
    		SPNavigationNode node = new SPNavigationNode("Bing", "http://www.bing.com");
    		topnav.AddAsLast(node);
    	}
    }

    More information:

    https://msdn.microsoft.com/en-us/library/office/gg277254%28v=office.14%29.aspx?f=255&MSPPError=-2147217396

    Or you can provide your code for further research the issue.

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, June 24, 2016 6:21 AM
  • Hello Dennis,

    I am using exact code you had specified. Only difference being URL is http:// abc.xyz.com/_layouts/viewlsts.aspx?BaseType=1

    Regards, Manu

    Sunday, June 26, 2016 6:35 AM
  • Hi,

    Any update?

    Please check the code below:

    using (SPSite site = new SPSite("http://sp2013"))
    {
    	using (SPWeb web = site.OpenWeb())
    	{
    		SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;
    		SPNavigationNode node = new SPNavigationNode("SiteContents", "/_layouts/viewlsts.aspx?BaseType=1");
    		topnav.AddAsLast(node);
    	}
    }

    If the code still not works, please check your account permission.

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Patrick_Liang Friday, July 1, 2016 9:17 AM
    • Marked as answer by Patrick_Liang Tuesday, July 5, 2016 9:05 AM
    Tuesday, June 28, 2016 2:29 AM
  • Hi Patrick,

    Thanks for response. As mentioned before, we are using same code & user account using which we are executing this code is "system account".

    We could identify the issue. Basically, SPNavigationNode checks if the resource belongs to current web if we dont pass "External flag" to true. https://msdn.microsoft.com/en-us/library/ms415159.aspx Apparently, one of the above node, path was belonging to other web. So, by using this flag, we could resolve the issue.

    Thanks lot for your response.

    Regards,

    Manu


    Regards, Manu

    Thursday, July 7, 2016 8:30 PM