SHARE
TWEET

Untitled

a guest Mar 20th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. internal static void CreatePhysicalFolderStructure(ClientContext context)
  2.     {
  3.         //get list of all folders from the zip file
  4.         var allFolders = Globals.FolderStructure.Descendants().Where(n => n.FolderLevel > 1).ToList();
  5.  
  6.         //get reference to the list
  7.         List list = context.Web.Lists.GetByTitle(Globals.DocLibName);
  8.  
  9.         CreateFolder(list, "Excel Files");
  10.         CreateFolder(list, "Excel Files/2013");
  11.         CreateFolder(list, "Excel Files/2013/PDF");
  12.  
  13.         'executes query
  14.         context.ExecuteQuery();
  15.     }
  16.     internal static void CreateFolder(List list, string name)
  17.     {
  18.         var info = new ListItemCreationInformation
  19.         {
  20.             UnderlyingObjectType = FileSystemObjectType.Folder,
  21.             LeafName = name
  22.         };
  23.         var newItem = list.AddItem(info);
  24.         newItem["Title"] = name;
  25.         newItem.Update();
  26.     }
  27.      
  28. private static IEnumerable<string> GetListFolderStructure(ClientContext context, List list)
  29.     {
  30.         var results = new List<string>();
  31.  
  32.         //query to recursively loop through all folders
  33.         var qry = new CamlQuery();
  34.         qry.ViewXml = "<View Scope='RecursiveAll'>" +
  35.                           "<Query>" +
  36.                               "<Where>" +
  37.                                     "<Eq>" +
  38.                                          "<FieldRef Name='FSObjType' />" +
  39.                                          "<Value Type='Integer'>1</Value>" +
  40.                                     "</Eq>" +
  41.                              "</Where>" +
  42.                            "</Query>" +
  43.                         "</View>";
  44.  
  45.         var allItems = list.GetItems(qry);
  46.         context.Load(allItems, n => n.Include(x => x.DisplayName, x => x.Folder));
  47.         context.ExecuteQuery();
  48.  
  49.         //retrieve default path that we will trim from our URL result
  50.         //e.g. Result we get from query is:     /sites/RobertTest/MainFolder/TestFolder/Word Files
  51.         //but we want to only return:           TestFolder/Word Files
  52.         string sDefaultPath = new Uri(Globals.SiteURL).AbsolutePath + "/" + Globals.DocLibName + "/";
  53.  
  54.         //add results to our List
  55.         foreach (var item in allItems)
  56.         {
  57.             results.Add(item.Folder.ServerRelativeUrl.Replace(sDefaultPath, ""));
  58.         }
  59.  
  60.         return results;
  61.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top