Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. using ITR.SharePoint.Client.CSOM;
  2. using Microsoft.SharePoint.Client;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace SP.DEMO.PROVISIONING {
  10. class Program {
  11. private static string username = "alnstrange@alnstrange.onmicrosoft.com";
  12. private static string siteURL = "https://alnstrange.sharepoint.com/sites/provisioning";
  13.  
  14. //Opret SharePoint Team Site
  15. //Opret liste med felter: Site Title, URL, IsProvisioned
  16. //Hent listen ud i koden
  17. //opret subsite på nye elementer
  18. //Ryd forsiden for webparts
  19. //Indsæt en Youtube video på forsiden (efter ejet valg)
  20.  
  21. static void Main(string[] args) {
  22. Console.WriteLine("Please enter password:");
  23. using (SPClientContext ctx = new SPClientContext(siteURL)) {
  24. ctx.Credentials = new SharePointOnlineCredentials(username, ctx.GetPasswordFromConsoleInput());
  25.  
  26. Web web = ctx.Web;
  27. ctx.Load(web);
  28. ctx.Load(web, x => x.Lists);
  29.  
  30. ctx.ExecuteQuery();
  31.  
  32. Console.WriteLine(string.Format("Connected to site with title of '{0}'", web.Title));
  33.  
  34. CamlQuery query = new CamlQuery();
  35. List myList = web.Lists.GetByTitle("testliste");
  36.  
  37. var myListFieldCollection = myList.Fields;
  38.  
  39. ListItemCollection websites = myList.GetItems(query);
  40. ctx.Load<List>(myList);
  41. ctx.Load<ListItemCollection>(websites);
  42. ctx.Load<FieldCollection>(myListFieldCollection);
  43. ctx.ExecuteQuery();
  44.  
  45. Console.WriteLine("Getting list items:");
  46.  
  47. var siteTitleColumnInternalName = myListFieldCollection.Single(t => t.Title == "Site Title").InternalName;
  48. var urlColumnInternalName = myListFieldCollection.Single(t => t.Title == "URL").InternalName;
  49. var isProvisionedTitleColumnInternalName = myListFieldCollection.Single(t => t.Title == "IsProvisioned").InternalName;
  50.  
  51. foreach (var website in websites)
  52. {
  53. Console.WriteLine(website.FieldValues.Single(k => k.Key == siteTitleColumnInternalName).Value);
  54. Console.WriteLine(website.FieldValues.Single(k => k.Key == urlColumnInternalName).Value);
  55. Console.WriteLine(website.FieldValues.Single(k => k.Key == isProvisionedTitleColumnInternalName).Value);
  56.  
  57.  
  58. //string isProvisioned = (string)item["IsProvisioned"];
  59. //Console.WriteLine(isProvisioned);
  60. }
  61.  
  62. Console.ReadLine();
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement