locked
SPNavigationNode does not contain a definition for cast? RRS feed

  • Question

  • public override void FeatureActivated(SPFeatureReceiverProperties properties) { // Get the web site where the feature is activated. SPWeb parentWeb = properties.Feature.Parent as SPWeb; if (parentWeb == null) return; SPWeb childWeb = null; string childName = "ourwiki"; // If a subsite by that name exists, open it. string[] webs = parentWeb.Webs.Names; if (webs != null && Array.IndexOf(webs, childName) >= 0) { childWeb = parentWeb.Webs[childName]; } // Otherwise, create the subsite. if (childWeb == null) { string title = "Wiki"; string desc = "A place to capture knowledge."; uint lcid = parentWeb.Language; string templateName = "WIKI#0"; childWeb = parentWeb.Webs.Add(childName, title, desc, lcid, templateName, false, false); } // Let the subsite use the parent site's top link bar. childWeb.Navigation.UseShared = true; // Get a collection of navigation nodes. SPNavigationNodeCollection nodes = null; if (parentWeb.Navigation.UseShared) { // Parent site does not have its own top link bar // so use the parent's Quick Launch. nodes = parentWeb.Navigation.QuickLaunch; } else { // Parent site has its own top link bar, // so use it. nodes = parentWeb.Navigation.TopNavigationBar; } // Check for an existing link to the subsite. SPNavigationNode node = nodes .Cast<SPNavigationNode>() .FirstOrDefault(n => n.Url.Equals(childWeb.ServerRelativeUrl)); // No link, so add one. if (node == null) { // Create the node. node = new SPNavigationNode(childWeb.Title, childWeb.ServerRelativeUrl); // Add it to the collection. node = nodes.AddAsLast(node); } childWeb.Dispose(); parentWeb.Dispose(); }

     

    Error 1 'Microsoft.SharePoint.Navigation.SPNavigationNodeCollection' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'Microsoft.SharePoint.Navigation.SPNavigationNodeCollection' could be found (are you missing a using directive or an assembly reference?) E:\Apps\SiteCreation\SiteCreation\Layouts\SiteCreation\ApplicationPage1.aspx.cs 51 43 SiteCreation


    rihdus
    Wednesday, May 18, 2011 1:01 PM

Answers

  • Cast<T> is an extension method defined in System.Linq namespace.

    Just include it in your .cs file:

     

    using System.Linq;
    

     


    Wednesday, May 18, 2011 1:33 PM

All replies

  • Cast<T> is an extension method defined in System.Linq namespace.

    Just include it in your .cs file:

     

    using System.Linq;
    

     


    Wednesday, May 18, 2011 1:33 PM
  • Thank you Bukharin i have deployed successfully but i couldn't create any site.
    rihdus
    Wednesday, May 18, 2011 4:20 PM