Guest User

Untitled

a guest
Dec 17th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
  2. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  3.  
  4. $SiteURL="https://xyz.sharepoint.com/sites/sample"
  5. $UserName="lz@xyz.onmicrosoft.com"
  6. $Password = "abc"
  7. $listName ="Special characters list"
  8.  
  9. $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
  10. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$SecurePassword)
  11.  
  12. #Bind to Site Collection
  13. $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
  14. $ctx.Credentials = $Creds
  15.  
  16. $list = $ctx.Web.Lists.GetByTitle($listName)
  17. $q = New-Object Microsoft.SharePoint.Client.CamlQuery
  18. $q.ViewXml = '<View Scope="RecursiveAll"><Query><Where><Eq><FieldRef Name="FSObjType" /><Value Type="Integer">1</Value></Eq></Where></Query></View>'
  19. $items = $list.GetItems($q)
  20. $ctx.Load($items)
  21. $ctx.ExecuteQuery()
  22. foreach($item in $items)
  23. {
  24. Write-Host -ForegroundColor green "id: " $item["FileRef"]
  25. }
  26.  
  27. string targetSiteURL = @"https://xyz.sharepoint.com/sites/sample";
  28.  
  29. var login = "lz@xyz.onmicrosoft.com";
  30. var password = "abc";
  31.  
  32. var listName = "Special characters list";
  33. var securePassword = new SecureString();
  34. foreach (char c in password)
  35. {
  36. securePassword.AppendChar(c);
  37. }
  38. SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
  39.  
  40. ClientContext ctx = new ClientContext(targetSiteURL);
  41. ctx.Credentials = onlineCredentials;
  42.  
  43. var list = ctx.Web.Lists.GetByTitle(listName);
  44. var q = new CamlQuery();
  45. q.ViewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where></Query></View>";
  46. var items = list.GetItems(q);
  47. ctx.Load(items);
  48. ctx.ExecuteQuery();
  49. foreach(var item in items)
  50. {
  51. Console.WriteLine("id: "+ item["FileRef"]);
  52. }
  53. Console.ReadLine();
Add Comment
Please, Sign In to add comment