我在此行收到错误
return folder.SubFolders.Aggregate(count, (current, subfolder) =>
GetFilesCount(subfolder, current));
错误是
错误1'Microsoft.SharePoint.SPFolderCollection'不包含'Aggregate'的定义,也没有扩展方法'Aggregate'接受类型'Microsoft.SharePoint.SPFolderCollection'的第一个参数可以找到(你错过了使用吗?指令或程序集引用?)
其余代码是
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));
}
}
}
我正在尝试创建一个Windows窗体应用程序,如下面的链接
我对使用演员阵容的线路进行了更改,但是它说了
return folder.SubFolders.Cast(count, (current, subfolder) =>
GetFilesCount(subfolder, current));
并且新错误是
错误1方法'Cast'没有重载需要'2'参数
答案 0 :(得分:5)
LINQ仅适用于通用集合
SPFolderCollection
实施IEnumerable
,但不是IEnumerable<SPFolder>
。
您需要致电.Cast<SPFolder>()
。