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,
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
LINQ only works on generic collections.
SPFolderCollectionimplementsIEnumerable, but notIEnumerable<SPFolder>.You need to call
.Cast<SPFolder>().