Tuesday, April 30, 2013
Get All Users from Web Application programatically
static void Main(string[] args)
{
String ConfigValues = ConfigurationSettings.AppSettings["WebAppsName"];
String[] ObjWebapps = ConfigValues.Split('|');
foreach (String WebappsName in ObjWebapps)
{
SPWebApplication webApp = SPWebApplication.Lookup(new Uri(WebappsName));
int count = webApp.Sites.Count;
foreach (SPSite ObjSites in webApp.Sites)
{
AllUsers(ObjSites.Url);
}
}
// AllUsers();
}
protected static void AllUsers(String SiteName)
{
using (SPSite site = new SPSite(SiteName))
{
using (SPWeb web = site.OpenWeb())
{
foreach (SPRoleAssignment roleAssignment in web.RoleAssignments)
{
if (roleAssignment.Member is SPGroup)
{
foreach (SPRoleDefinition roleDefinition in roleAssignment.RoleDefinitionBindings)
{
// ("\t" + roleDefinition.Name);
if (roleDefinition.Name.Equals("Contribute"))
{
var group = (SPGroup)roleAssignment.Member;
foreach (SPUser user in group.Users)
{
//("Contribute Permission Level" + "----" + "User Name" + user.Name);
}
}
if (roleDefinition.Name.Equals("Full Control"))
{
var group = (SPGroup)roleAssignment.Member;
foreach (SPUser user in group.Users)
{
//("Contribute Permission Level" + "----" + "User Name" + user.Name);
}
}
if (roleDefinition.Name.Equals("Read"))
{
var group = (SPGroup)roleAssignment.Member;
foreach (SPUser user in group.Users)
{
//("Read Permission Level" + "----" + "User Name" + user.Name);
}
}
if (roleDefinition.Name.Equals("View Only"))
{
var group = (SPGroup)roleAssignment.Member;
foreach (SPUser user in group.Users)
{
//("View Only Permission Level" + "----" + "User Name" + user.Name);
}
}
}
}
}
}
}
}
Thursday, March 14, 2013
SharePoint List items in Modal Dialog Popup from CQWW or XSLT
SharePoint List items in Modal Dialog Popup from
CQWP or XSLT
Open list items in Modal dialog listed in Content Query Web Part.
Steps to do
- Open Site with in SharePoint designer and go to All items > Style library> XSL Style Sheets.
- Open ItemStyle.xsl file and edit it (CheckOut \ take the backup for safe)
- Paste below section to any of the </xsl:template>
<xsl:template name="ModalDialogPopUp" match="Row[@Style='ModalDialogPopUp']" mode="itemstyle">
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="@Title"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<div class="item link-item
bullet">
<xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
<a onclick="javascript:SP.UI.ModalDialog.ShowPopupDialog('{$SafeLinkUrl}');
return false;" onmouseover="javascript:this.style.cursor='hand';" title="{@LinkToolTip}">
<xsl:value-of select="$DisplayTitle"/>
</a>
</div>
</xsl:template>
4. Save the file and check it in.
5. Edit CQWP, ==> Presents==> in the ItemStyle of CQWP Select from Dropdown as ModalDialogPopUp and Click OK.
Wednesday, March 13, 2013
Accessing Remote Active Directory User Properties in C#
Accessing Remote Active Directory User Properties in C#.
// Active Directory Access & Country Retrival
SearchResultCollection sResults = null;
string path = "LDAP://IPAddress"; .. (string path ="LDAP://10.0.2.15";)
DirectoryEntry dEntry = new DirectoryEntry(path, "Domain\\UserName", "Password");
DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
dSearcher.Filter = "(&(objectClass=user)(SAMAccountName=" + myname + "))";
sResults = dSearcher.FindAll();
String DisplayNames = String.Empty;
foreach (SearchResult searchResult in sResults)
{
if (searchResult != null)
{
DisplayNames = searchResult.Properties["cn"][0].ToString();
if (DisplayNames.Contains("RKU.DK"))
{
String CountryName = searchResult.Properties["c"][0].ToString();
//("Country Name...:" + CountryName);
}
}
}
---------------------------------------------------------------------------------------------------
CODES in ACTIVE DIRECTORY Property:
// Active Directory Access & Country Retrival
SearchResultCollection sResults = null;
string path = "LDAP://IPAddress"; .. (string path ="LDAP://10.0.2.15";)
DirectoryEntry dEntry = new DirectoryEntry(path, "Domain\\UserName", "Password");
DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
dSearcher.Filter = "(&(objectClass=user)(SAMAccountName=" + myname + "))";
sResults = dSearcher.FindAll();
String DisplayNames = String.Empty;
foreach (SearchResult searchResult in sResults)
{
if (searchResult != null)
{
DisplayNames = searchResult.Properties["cn"][0].ToString();
if (DisplayNames.Contains("RKU.DK"))
{
String CountryName = searchResult.Properties["c"][0].ToString();
//("Country Name...:" + CountryName);
}
}
}
---------------------------------------------------------------------------------------------------
CODES in ACTIVE DIRECTORY Property:
OBJECTCLASS = "objectClass";
=>. CONTAINERNAME = "cn";
=>. LASTNAME = "sn";
=>. COUNTRYNOTATION = "c";
=>. CITY = "l";
=>. STATE = "st";
=>. TITLE = "title";
=>. POSTALCODE = "postalCode";
=>. PHYSICALDELIVERYOFFICENAME = "physicalDeliveryOfficeName";
=>. FIRSTNAME = "givenName";
=>. MIDDLENAME = "initials";
=>. DISTINGUISHEDNAME = "distinguishedName";
=>. INSTANCETYPE = "instanceType";
=>. WHENCREATED = "whenCreated";
=>. WHENCHANGED = "whenChanged";
=>. DISPLAYNAME = "displayName";
=>. USNCREATED = "uSNCreated";
=>. MEMBEROF = "memberOf";
=>. USNCHANGED = "uSNChanged";
=>. COUNTRY = "co";
=>. DEPARTMENT = "department";
=>. COMPANY = "company";
=>. PROXYADDRESSES = "proxyAddresses";
=>. STREETADDRESS = "streetAddress";
=>. DIRECTREPORTS = "directReports";
=>. NAME = "name";
=>. OBJECTGUID = "objectGUID";
=>. USERACCOUNTCONTROL = "userAccountControl";
=>. BADPWDCOUNT = "badPwdCount";
=>. CODEPAGE = "codePage";
=>. COUNTRYCODE = "countryCode";
=>. BADPASSWORDTIME = "badPasswordTime";
=>. LASTLOGOFF = "lastLogoff";
=>. LASTLOGON = "lastLogon";
=>. PWDLASTSET = "pwdLastSet";
=>. PRIMARYGROUPID = "primaryGroupID";
=>. OBJECTSID = "objectSid";
=>. ADMINCOUNT = "adminCount";
=>. ACCOUNTEXPIRES = "accountExpires";
=>. LOGONCOUNT = "logonCount";
=>. LOGINNAME = "sAMAccountName";
=>. SAMACCOUNTTYPE = "sAMAccountType";
=>. SHOWINADDRESSBOOK = "showInAddressBook";
=>. LEGACYEXCHANGEDN = "legacyExchangeDN";
=>. USERPRINCIPALNAME = "userPrincipalName";
=>. EXTENSION = "ipPhone";
=>. SERVICEPRINCIPALNAME = "servicePrincipalName";
=>. OBJECTCATEGORY = "objectCategory";
=>. DSCOREPROPAGATIONDATA = "dSCorePropagationData";
=>. LASTLOGONTIMESTAMP = "lastLogonTimestamp";
=>. EMAILADDRESS = "mail";
=>. MANAGER = "manager";
=>. MOBILE = "mobile";
=>. PAGER = "pager";
=>. FAX ="facsimileTelephoneNumber";
=>. HOMEPHONE = "homePhone";
Subscribe to:
Posts (Atom)