Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:53:37+00:00 2026-05-27T13:53:37+00:00

I am receiving an error at this line return folder.SubFolders.Aggregate(count, (current, subfolder) => GetFilesCount(subfolder,

  • 0

I am receiving an error at this line

return folder.SubFolders.Aggregate(count, (current, subfolder) =>
               GetFilesCount(subfolder, current));

Error is

Error 1 ‘Microsoft.SharePoint.SPFolderCollection’ does not contain a definition for ‘Aggregate’ and no extension method ‘Aggregate’ accepting a first argument of type ‘Microsoft.SharePoint.SPFolderCollection’ could be found (are you missing a using directive or an assembly reference?)

Rest of code is

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using Microsoft.SharePoint;
using System.Windows.Controls;
using System.IO;
using System.Collections;

 namespace WindowsFormsApplication1
 {
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (SPSite currentSite = new SPSite(txtSiteAddress.Text))
                {
                    SPWeb currentweb = currentSite.OpenWeb();
                    var webtree = new TreeViewItem();
                    webtree.Header = currentweb.Title;
                    webtree.Tag = currentweb;
                    MapFolders(currentweb.Folders, webtree);    
                }
             }
             catch (Exception a)
             {
                MessageBox.Show(a.ToString());
             }
        }

        private void MapFolders(SPFolderCollection folderList,
                                             TreeViewItem treeNode)
        {
            for (var i = 0; i < folderList.Count; i++)
            {
                var item = new TreeViewItem();
                item.Header = string.Format("{0} ({1})", folderList[i].Name,
                                             GetFilesCount(folderList[i], 0));
                item.Tag = folderList[i];

                treeNode.Items.Add(item);

                if (folderList[i].SubFolders.Count > 0)
                    MapFolders(folderList[i].SubFolders, item);
            }
        }

        private int GetFilesCount(SPFolder folder, int count)
        {
            count += folder.Files.Count;

            return folder.SubFolders.Aggregate(count, (current, subfolder) =>
                   GetFilesCount(subfolder, current));
        }



    }
}

I am trying to make a windows form application, as in link below,

enter link description here

I Made Changes to the line to use cast but its says

return folder.SubFolders.Cast(count, (current, subfolder) =>
               GetFilesCount(subfolder, current));

and new Error is

Error 1 No overload for method ‘Cast’ takes ‘2’ arguments

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:53:38+00:00Added an answer on May 27, 2026 at 1:53 pm

    LINQ only works on generic collections.
    SPFolderCollection implements IEnumerable, but not IEnumerable<SPFolder>.

    You need to call .Cast<SPFolder>().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm receiving suddenly this error on a Win2003 Server Web Application: Microsoft VBScript runtime
I am receiving this error: File /DateDbLoop.py, line 33 d.Id % (str(day), str(2840)) ^
I'm receiving the following error on this line of code select.up().appendChild(sw); With error SCRIPT438:
I'm receiving this error in my Linq statement --- Cannot implicitly convert type 'System.Collections.Generic.IEnumerable'
I am receiving this error. I have no clue as to why it would
I am currently receiving this error: Validation of viewstate MAC failed. If this application
I am not sure what the problem is but I keep receiving this error
I'm having trouble overriding a ModelForm save method. This is the error I'm receiving:
In my program, I have been receiving an error when I use a command-line
I'm using phoenix::bind and receiving this error message: error C2039: 'bind' : is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.