Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET引用(未找到方法)_C#_.net_Sharepoint - Fatal编程技术网

C# .NET引用(未找到方法)

C# .NET引用(未找到方法),c#,.net,sharepoint,C#,.net,Sharepoint,我在这一行收到一个错误 return folder.SubFolders.Aggregate(count, (current, subfolder) => GetFilesCount(subfolder, current)); 错误是 错误1“Microsoft.SharePoint.SPFolderCollection”不包含“聚合”的定义,并且找不到接受类型为“Microsoft.SharePoint.SPFolderCollection”的第一个参数的

我在这一行收到一个错误

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

错误1“Microsoft.SharePoint.SPFolderCollection”不包含“聚合”的定义,并且找不到接受类型为“Microsoft.SharePoint.SPFolderCollection”的第一个参数的扩展方法“聚合”(是否缺少using指令或程序集引用?)

代码的其余部分是

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));
        }



    }
}
新的错误是

错误1方法“Cast”没有重载接受“2”个参数


LINQ仅适用于通用集合。
SPFolderCollection
实现
IEnumerable
,但不实现
IEnumerable


您需要调用
.Cast()

LINQ仅适用于一般集合。
SPFolderCollection
实现
IEnumerable
,但不实现
IEnumerable


你需要调用
.Cast()

你能解释一下吗我在这里发帖之前已经读过了,但是我发现有点难以理解:/,因为我甚至不明白这行代码在做什么:(…
.Cast()
创建一个
IEnumerable
来包装一个非类型的
IEnumerable
。这允许您使用LINQ扩展方法。@user1090104,提供的链接SLaks有一个示例。除非“示例”是指“为我编写代码”。SLaks不会在每次需要编写代码时出现;你必须自己学习如何编写代码。@DourHighArch学习和自己编写代码很好,但他明确表示自己尝试过,并且很难理解。我们都从某个地方开始,至少他在来问之前努力研究,给他们一些信任你能解释一下吗我在这里发帖之前已经读过了,但是我发现有点难以理解:/,因为我甚至不明白这行代码在做什么:(…
.Cast())
创建一个
IEnumerable
来包装一个非类型的
IEnumerable
。这允许您使用LINQ扩展方法。@user1090104,提供的链接SLaks有一个示例。除非“示例”是指“为我编写代码”。SLaks不会在每次需要编写代码时出现;你必须自己学习如何编写代码。@DourHighArch学习和自己编写代码很好,但他明确表示自己尝试过,并且很难理解。我们都从某个地方开始,至少他在来问之前努力研究,给他们一些信任信息技术
return folder.SubFolders.Cast(count, (current, subfolder) =>
               GetFilesCount(subfolder, current));