Muh*_*aja 1 .net c# sharepoint
我在这一行收到错误
return folder.SubFolders.Aggregate(count, (current, subfolder) =>
GetFilesCount(subfolder, current));
Run Code Online (Sandbox Code Playgroud)
错误是
错误1'Microsoft.SharePoint.SPFolderCollection'不包含'Aggregate'的定义,也没有扩展方法'Aggregate'接受类型为'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));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试制作一个Windows窗体应用程序,如下面的链接,
我对使用演员阵容的线路进行了更改,但它说
return folder.SubFolders.Cast(count, (current, subfolder) =>
GetFilesCount(subfolder, current));
Run Code Online (Sandbox Code Playgroud)
和新的错误是
错误1方法'Cast'没有重载需要'2'参数
LINQ仅适用于通用集合.
SPFolderCollection实现IEnumerable,但不是IEnumerable<SPFolder>.
你需要打电话.Cast<SPFolder>().
| 归档时间: |
|
| 查看次数: |
932 次 |
| 最近记录: |