title: SharePoint 2010 Client Object Model Add Sharepoint user/group to every document library folder programatically
body: <p>I have the code below that I cobbled together via various pieces found via google search etc. </p>
  
  <p>The code works like a champ to provide a treeview of the various libraries and folders within them. </p>
  
  <p>Recently we had an important user accidentally removed from the system and when that happened, it was also removed from every library &amp; folder it was it (which was every single one).. (we have broken the permissions for every folder and do not inherit permissions at library or folder levels) </p>
  
  <p>I figured this app code goes recursively through all the libraries and folders on the site... I could just add a bit of code to add the user to each folder with it. </p>
  
  <p>My problem is that every example/suggestion I've found so far has Folder.item.blahblahblah
  but I have no method called "item" in my folder object(s)</p>
  
  <p>Any hints or outright step-by-step fixes for my code below to do what I need?</p>
  
  <pre><code>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" &amp;&amp; !list.IsApplicationList &amp;&amp; list.Title != "Form Templates" &amp;&amp; list.Title != "Customized Reports" &amp;&amp; list.Title != "Site Collection Documents" &amp;&amp; list.Title != "Site Collection Images" &amp;&amp; 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!");
  
              }
          }
      }
  }
  </code></pre>