Guest User

Untitled

a guest
Apr 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. string siteURL = ConfigurationManager.AppSettings["siteURL"];
  2. string userName = ConfigurationManager.AppSettings["userName"];
  3. string password = ConfigurationManager.AppSettings["password"];
  4.  
  5. ClientContext clientContext = new ClientContext(siteURL);
  6. SecureString securePassword = new SecureString();
  7. foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
  8. clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
  9.  
  10. Web web = clientContext.Web;
  11. ListCollection listCollection = clientContext.Web.Lists;
  12. clientContext.Load(
  13. listCollection,
  14. lists => lists
  15. .Include(
  16. list => list.Title,
  17. list => list.Hidden,
  18. list => list.RootFolder.Files)
  19. .Where(list => !list.Hidden)
  20. );
  21. clientContext.ExecuteQuery();
  22. FileCollection files = listCollection.Where(x => x.Title == "Documents").FirstOrDefault().RootFolder.Files;
  23. File file = files.Where(x => x.Name == "Excel_File.xlsx").FirstOrDefault();
Add Comment
Please, Sign In to add comment