-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
185 lines (157 loc) · 6.12 KB
/
MainForm.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SharePointSiteOwnerTools
{
public partial class MainForm : System.Windows.Forms.Form
{
private static string currentBaseSiteStatus;
public MainForm()
{
InitializeComponent();
currentBaseSiteStatus = Properties.Settings.Default.currentBaseUrl;
txtBoxCurrentStatus_BaseSiteSetAs.Text = currentBaseSiteStatus;
txtBoxSiteUrl.Text = currentBaseSiteStatus;
chkboxIsSiteAdmin.Checked = Properties.Settings.Default.currentAuthUserIsSiteAdmin;
}
public static class CurrentStatus
{
public static string currentBaseUrl
{
get { return Properties.Settings.Default.currentBaseUrl; }
set
{
Properties.Settings.Default.currentBaseUrl = value;
Properties.Settings.Default.Save();
}
}
public static string currentAuthUser
{
get { return Properties.Settings.Default.currentAuthUser; }
set
{
Properties.Settings.Default.currentAuthUser = value;
Properties.Settings.Default.Save();
}
}
public static bool currentAuthUserIsAdmin
{
get { return Properties.Settings.Default.currentAuthUserIsSiteAdmin; }
set
{
Properties.Settings.Default.currentAuthUserIsSiteAdmin = value;
Properties.Settings.Default.Save();
}
}
}
private void btnSetSite_Click(object sender, EventArgs e)
{
Regex httpRegex = new Regex("^(http|https)://");
string strTargetString = @txtBoxSiteUrl.Text; // put here value from text box
if (httpRegex.IsMatch(strTargetString))
{
//MessageBox.Show("Correct");
CurrentStatus.currentBaseUrl = txtBoxSiteUrl.Text;
txtBoxCurrentStatus_BaseSiteSetAs.Text = CurrentStatus.currentBaseUrl;
}
else
{
MessageBox.Show("Incorrect input - Site Url must start with http:// or https://");
}
//Properties.Settings.Default.currentBaseUrl = txtBoxSiteUrl.Text;
}
private void txtBoxSiteUrl_TextChanged(object sender, EventArgs e)
{
}
private void btnTestAccess_Click(object sender, EventArgs e)
{
Regex httpRegex = new Regex("^(http|https)://");
string strTargetString = txtBoxSiteUrl.Text;
if (httpRegex.IsMatch(strTargetString))
{
ClientContext ctx = SPAuth.GetWebLoginClientContext(strTargetString);
Web web = ctx.Web;
ctx.Load(web, w => w.Title, w => w.CurrentUser);
ctx.ExecuteQuery();
//currentAuthUser
CurrentStatus.currentAuthUser = web.CurrentUser.Email.ToString();
CurrentStatus.currentAuthUserIsAdmin = web.CurrentUser.IsSiteAdmin;
chkboxIsSiteAdmin.Checked = CurrentStatus.currentAuthUserIsAdmin;
string confirmWebText = "You have connected to site: " + web.Title + " using Interactive Web Login!";
Console.WriteLine("You have connected to {0} site, using Interactive Web Login!", web.Title);
System.Windows.Forms.MessageBox.Show(confirmWebText);
}
else
{
MessageBox.Show("Incorrect input - Site Url must start with http:// or https://");
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnBaseSiteDetails_Click(object sender, EventArgs e)
{
BaseSiteDetailsForm frm = new BaseSiteDetailsForm();
frm.Show();
}
private void btnRetrieveAllSiteLists_Click(object sender, EventArgs e)
{
AllSiteListsForm frm = new AllSiteListsForm();
frm.Show();
}
private void btnOpenSiteInDefaultBrowser_Click(object sender, EventArgs e)
{
openInDefaultBrowser(CurrentStatus.currentBaseUrl);
}
private void openInDefaultBrowser(string targetUrl)
{
try
{
System.Diagnostics.Process.Start(targetUrl);
}
catch (System.ComponentModel.Win32Exception noBrowser)
{
if (noBrowser.ErrorCode == -2147467259)
MessageBox.Show(noBrowser.Message);
}
catch (System.Exception other)
{
MessageBox.Show(other.Message);
}
}
//private void btnRetrieveSiteMemberGroups_Click(object sender, EventArgs e)
//{
// ArrayList memGroupList = new ArrayList();
// ClientContext ctx = SPAuth.GetWebLoginClientContext(CurrentStatus.currentBaseUrl);
// memGroupList = SPOps.getAllSPMemberGroups(ctx);
// foreach(var memGroup in memGroupList)
// {
// lstBoxMemberGroups.Items.Add(memGroup);
// }
//}
private void btnGetSitePermissions_Click(object sender, EventArgs e)
{
SPPermissionsForm sPPermissions = new SPPermissionsForm();
sPPermissions.Show();
}
private void toolTip1_Popup(object sender, PopupEventArgs e)
{
}
private void btnGetSiteStructureTree_Click(object sender, EventArgs e)
{
SubSitesForm sPSubSitesForm = new SubSitesForm();
sPSubSitesForm.Show();
}
}
}