gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 20:29:06 24 4
gpt4 key购买 nike

我在这一行收到一个错误

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

错误是

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?)

其余代码是

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 窗体应用程序,如下面的链接所示,

enter link description here

我更改了行以使用 cast 但它说

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

新的错误是

Error 1 No overload for method 'Cast' takes '2' arguments

最佳答案

LINQ 仅适用于泛型集合。
SPFolderCollection工具 IEnumerable , 但不是 IEnumerable<SPFolder> .

您需要调用.Cast<SPFolder>() .

关于c# - .NET 引用(未找到方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8564605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com