-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSharepointHelpper.cs
More file actions
65 lines (52 loc) · 1.69 KB
/
SharepointHelpper.cs
File metadata and controls
65 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
// Must import NuGet Microsoft.SharePointOnline.CSOM
// https://msdn.microsoft.com/en-us/library/office/jj193041.aspx
namespace BrowserAPP
{
public struct typBanners
{
public string Msg;
public DateTime From;
public DateTime To;
public bool Enabled;
}
public struct typButtons
{
public string Title;
public string URL;
}
class SharepointHelpper
{
public static ListItemCollection GetList(string listName)
{
var tenant = BrowserAPP.Properties.Settings.Default.SPSite; //Must set the sharepoint site url
var userName = BrowserAPP.Properties.Settings.Default.SPUser; //username
var passwordString = BrowserAPP.Properties.Settings.Default.SPPass; //password
using (var ctx = new ClientContext(tenant))
{
//Provide count and pwd for connecting to the source
var passWord = new SecureString();
foreach (var c in passwordString.ToCharArray()) passWord.AppendChar(c);
ctx.Credentials = new SharePointOnlineCredentials(userName, passWord);
// Actual code for operations
var web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
//Get my list
var query = new CamlQuery();
var myList = web.Lists.GetByTitle(listName);
var kundeItems = myList.GetItems(query);
ctx.Load<List>(myList);
ctx.Load<ListItemCollection>(kundeItems);
ctx.ExecuteQuery();
return kundeItems;
}
}
}
}