以下のコードは、Google検索などで見つけたさまざまな部分を組み合わせてまとめたものです。
コードはチャンピオンのように機能し、さまざまなライブラリとその中のフォルダーのツリービューを提供します。
最近、重要なユーザーが誤ってシステムから削除され、それが発生したときに、すべてのライブラリとフォルダー (すべてのフォルダー) からも削除されました (すべてのフォルダーのアクセス許可が壊れており、継承されていません)。ライブラリまたはフォルダー レベルでのアクセス許可)
私は、このアプリ コードがサイト上のすべてのライブラリとフォルダーを再帰的に通過すると考えました...各フォルダーにユーザーを追加するコードを少し追加するだけで済みます。
私の問題は、これまでに見つけたすべての例/提案にFolder.item.blahblahblahがありますが、フォルダーオブジェクトに「アイテム」と呼ばれるメソッドがないことです
以下のコードで必要なことを行うためのヒントや完全な段階的な修正はありますか?
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!");
}
}
}
}