我有下面的代码我拼凑通过通过谷歌找到各条搜索等的SharePoint 2010客户端对象模型添加SharePoint用户/组的每一个文档库文件夹编程
代码工作就像一个冠军提供其中的各种库和文件夹的树视图。
最近我们有一个重要的用户意外地从系统中删除,当它发生时,它也被从每个库中删除&它是它(它是每一个)文件夹..(我们打破了每个文件夹的权限并且不会在库或文件夹级别继承权限)
我想这个应用程序代码通过网站上的所有库和文件夹递归地递归...我可以添加一些代码来将用户添加到每个文件夹它。
我的问题是,每一个例子/建议,到目前为止,我已经找到了Folder.item.blahblahblah 但我已经在我的文件夹中的对象(S)
任何提示或干脆一步称为“项”没有方法逐步修复下面我的代码来做我所需要的?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint.Client;
using System.Net;
namespace red
{
public partial class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "It Begins...\r\n";
string SitenameDev = @"https://portal/sites/devv/team";
string SitenameProd = @"https://portal/sites/";
ClientContext clientcontext = new ClientContext(SitenameProd);
clientcontext.Credentials = new NetworkCredential("sitecollectionadminacct", "pswd", "Domain");
//Load Libraries from SharePoint
clientcontext.Load(clientcontext.Web.Lists);
clientcontext.ExecuteQuery();
foreach (List list in clientcontext.Web.Lists)
{
try
{
if (list.BaseType.ToString() == "DocumentLibrary" && !list.IsApplicationList && list.Title != "Form Templates" && list.Title != "Customized Reports" && list.Title != "Site Collection Documents" && list.Title != "Site Collection Images" && list.Title != "Images")
{
clientcontext.Load(list);
clientcontext.ExecuteQuery();
clientcontext.Load(list.RootFolder);
clientcontext.Load(list.RootFolder.Folders);
clientcontext.Load(list.RoleAssignments);
clientcontext.ExecuteQuery();
TreeViewLibraries.ShowLines = true;
TreeNode LibraryNode = new TreeNode(list.Title);
//MessageBox.Show(LibraryNode.Name);
TreeViewLibraries.Nodes.Add(LibraryNode);
if (!list.Title.StartsWith("Nothing here"))
{
foreach (Folder SubFolder in list.RootFolder.Folders)
{
if (SubFolder.Name != "Forms")
{
TreeNode MainNode = new TreeNode(SubFolder.Name);
LibraryNode.Nodes.Add(MainNode);
FillTreeViewNodes(SubFolder, MainNode, clientcontext);
}
}
}
}
}
catch (Exception eee)
{
}
}
}
//Recursive Function
public void FillTreeViewNodes(Folder SubFolder, TreeNode MainNode, ClientContext clientcontext)
{
clientcontext.Load(SubFolder.Folders);
clientcontext.ExecuteQuery();
foreach (Folder Fol in SubFolder.Folders)
{
TreeNode SubNode = new TreeNode(Fol.Name);
MainNode.Nodes.Add(SubNode);
FillTreeViewNodes(Fol, SubNode, clientcontext);
//ListItem Fole = new ListItem();
}
}
private void TreeViewLibraries_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
MessageBox.Show("Node: " + e.Node.Text);
try
{
MessageBox.Show("Parent: " + e.Node.Parent.Text);
}
catch (System.NullReferenceException)
{
MessageBox.Show("Parent: " + "None!");
}
}
}
}
建议:停止忽略异常,甚至不要使用_try_来捕获'NullReferenceException'。 – 2013-04-04 01:05:43
@JohnSaunders我明白,例外情况不应该被忽略。这还没有充实代码。几乎证明了我的概念,如果我将来需要类似的东西,我就会保存下来。原来我可以,但仍然没有弄清楚为什么我无法访问roleAssignment当Im循环通过文件夹。感谢链接到“应该......”顺便说一句,我会把它读一读。 – Tony 2013-04-04 13:21:21