Vito Cagnazzo SharePoint
3.4.15
Create Site SharePoint Rest C# CSOM
private static string GetFormDigest(string token, string hdnHostWeb)
{
/* Retrieve a form digest, which is required for creating a new list item */
string endpoint = hdnHostWeb + "/_api/contextinfo";
HttpWebRequest digestRequest = (HttpWebRequest)HttpWebRequest.Create(endpoint);
digestRequest.Headers.Add("Authorization", "Bearer " + token);
digestRequest.Method = "POST";
digestRequest.ContentLength = 0;
HttpWebResponse digestResponse = (HttpWebResponse)digestRequest.GetResponse();
XDocument responseDoc = XDocument.Load(digestResponse.GetResponseStream());
XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
string formDigest = responseDoc.Descendants(d + "FormDigestValue").First().Value;
return formDigest;
}
public static Web CreateSite(string token, ClientContext cc, Web currentWeb, string template, int langue, bool heritage, string description, string titre, string url)
{
Web web = null;
try
{
#region test
string itemXML = "{'parameters': {'__metadata': {'type': 'SP.WebInfoCreationInformation' },'Url': '" + url + "','Title': '" + titre + "','Description': '" + description + "','Language':" + langue + ",'WebTemplate':'" + template + "','UseUniquePermissions':'" + !heritage + "'}}";
HttpWebRequest restRequest = (HttpWebRequest)HttpWebRequest.Create(currentWeb.Url + "/_api/web/webinfos/add");
restRequest.Headers.Add("Authorization", "Bearer " + token);
restRequest.Credentials = CredentialCache.DefaultCredentials;
restRequest.Method = "POST";
restRequest.Headers["X-RequestDigest"] = GetFormDigest(token, currentWeb.Url);
restRequest.Accept = "application/json;odata=verbose";
restRequest.ContentType = "application/json;odata=verbose";
restRequest.ContentLength = itemXML.Length;
StreamWriter sw = new StreamWriter(restRequest.GetRequestStream());
sw.Write(itemXML);
sw.Flush();
//Get response
HttpWebResponse restResponse = (HttpWebResponse)restRequest.GetResponse();
StreamReader restStream = new StreamReader(restResponse.GetResponseStream());
#endregion
cc.Load(cc.Web.Webs);
cc.ExecuteQuery();
foreach (Web wb in cc.Web.Webs)
{
if (wb.Title == titre || wb.Url == url)
{
web = wb;
}
}
.....
2.4.15
Javascript MemberOf Group AD, query LDAP ( activeX enabled /!\ and only in IE /!\)
var ldapSearchJs = ldapSearchJs || {};
ldapSearchJs.getUserName = function () {
var wshNetwork = new ActiveXObject("WScript.Network");
var userName = wshNetwork.UserName;
return userName;
}
ldapSearchJs.isMemberOf = function (userName, group) {
objConnection = new ActiveXObject("ADODB.Connection");
objConnection.Provider = "ADsDSOObject";
objConnection.Open("ADs Provider");
objCommand = new ActiveXObject("ADODB.Command");
objCommand.ActiveConnection = objConnection;
objCommand.CommandText = "SELECT distinguishedName, memberOf, primaryGroupID, objectSID FROM 'LDAP://DC=vca-share,DC=local' "
+ " WHERE sAMAccountName='" + userName + "' and memberof='CN=" + group + ",CN=Users,DC=vca-share,DC=local'"; //(memberOf=cn=adminsp,ou=users,dc=vca-share,DC=local))";
objRecordSet = objCommand.Execute();
var userMail, lastName, firstName;
if (objRecordSet.RecordCount > 0) {
isMemberOf = 'Yes, ' + userName + ' is memeber of ' + group;
}
else {
isMemberOf = 'No';
}
objConnection.Close;
return isMemberOf;
}
$(document).ready(function () {
alert(
ldapSearchJs.isMemberOf(ldapSearchJs.getUserName(), 'adminsp')
);
});
Subscribe to:
Posts (Atom)