Sharing SharePoint

Always a rookie in the SharePoint World

  • Follow me on Twitter

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

  • Blog Stats

    • 59,184 hits
  • Advertisements

Archive for the ‘WebParts’ Category

Display site members from AD Groups

Posted by Jessica Wang on July 13, 2008

I recently have to do this for a client. The web part is suppose to display a list of all users from the Sharepoint Security groups for every site. The out of the box webpart(Site Users) will display only the name of the AD group and not the members within it.

To get started, it is easier if you installed the Webpart templates for VS.NET

Created a solution using webpart template and you are ready to go.

Call this function to pass in the name of the ADgroup and it will return a list of users name.

//Query Active Directory to get users from Active Directory Groups

public StringCollection GetGroupMembers(stringstrGroup)

{StringCollection groupMemebers = new StringCollection(); 


{DirectoryEntry ent = new DirectoryEntry(LDAP://OU=youOU,DC=yourDC);

DirectorySearcher srch = new DirectorySearcher(“(CN=” + strGroup + “)”);

SearchResultCollection coll = srch.FindAll(); 

foreach (SearchResult rs in coll)

{ResultPropertyCollection resultPropColl = rs.Properties;

foreach (Object memberColl in resultPropColl[“member”])

{DirectoryEntry gpMemberEntry = new DirectoryEntry(“LDAP://”+ memberColl);

System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties;

//getting user properties from AD

object obVal = userProps[“displayName”].Value;

object obAcc = userProps[“sAMAccountName”].Value;

if (null != obVal) {

 groupMemebers.Add( “User Name:” +obAcc.ToString() + “, User login name:” + obVal.ToString() + “<br>”);}}}}

catch (Exception ex)


Return groupMemebers;

To get the names of the current site users from Sharepoint Security Groups:

ArrayList belongToDomain = new ArrayList();

ArrayList names = new ArrayList();

using(SPSite collSite = new SPSite(SPContext.Current.Site.ID))

{using (SPWeb elevatedWeb = collSite.OpenWeb(SPContext.Current.Web.ID))

{//All users in the site

SPUserCollection collUser = SPContext.Current.Web.AllUsers;

SPGroupCollection collgroup = SPContext.Current.Web.Groups;

//for each item in the collection of groups

foreach (object group in collgroup){

//display all users other then the visitors

if (group.ToString() != “Visitors”){

//check that the users in the whole site collection belongs to current site group

foreach (SPUser singleuser in collUser)

{//get the list of groups that the user belongs to

foreach (SPGroup userGroup in singleuser.Groups)

{//check if it matches any of the current site groups

if (group.ToString() == userGroup.ToString())

{//check if the user from the sharepoint group is a AD group

if (singleuser.IsDomainGroup)

{//pass the name into Array that query the AD



//otherwise add into the Array that stores list of names, in case the user name is not from an AD group.


);}} }}}}}}

Now that we have the names of the AD groups from the share point security groups and query the AD for a list of user name. It is now in the names array, we need to make sure that there are no duplicate names. So call the function below and pass in the names array.

//remove duplicate users name Function

public ArrayList RemoveDups(ArrayList items)


 ArrayList noDups = new ArrayList();

 foreach (string strItem in items)


        if (!noDups.Contains(strItem.Trim()))






    return noDups;}


Posted in WebParts | Tagged: , , , , | 10 Comments »

Customizing RSS Viewer to display forecast

Posted by Jessica Wang on March 25, 2008

Step 1:  Register for Free at to get your Partner ID and License Key

Step 2: Enter*&dayf=6&par=PartnerID&prod=xoap&unit=m&key=LicenseKey into RSS Feed URL

Step 3: Edit the XSL

<?xml version=”1.0″ encoding=”ISO-8859-1″ ?><xsl:stylesheet version=”1.0″ xmlns:xsl=””><xsl:output method=”html” indent=”yes” encoding=”iso-8859-1″ /><xsl:template match=”/weather”>

<xsl:variable name=”med-img-dir”>WeatherIcons/60×59</xsl:variable>

<!–Purpose: Weather Webpart, information from–>

         <xsl:variable name=”day” select=”dayf/day[@d]”></xsl:variable>

        <xsl:for-each select=”$day”>

 <!– Current Weather Conditions –>

<table width=”100%”>



                                <td style=”width: 70px;font-size: 11px” rowspan=”3″>

                                <xsl:variable name=”img-ext”>png</xsl:variable>

                                <xsl:variable name=”iconnumber” select=”part[@p=’d’]/icon” />

                                <img src=”{$med-img-dir}/{$iconnumber}.{$img-ext}” mce_src=”{$med-img-dir}/{$iconnumber}.{$img-ext}” alt=”{$iconnumber}.{$img-ext}” width=”40″ height=”42″ />


                                <!–Day and Date–>

                                <td style=”font-size: 11px; font-weight: bold; padding:0px 0px 0px 0px” colspan=”2″>

                                                                <xsl:value-of select=”./@dt” />,

                                                                <xsl:value-of select=”./@t” />




                                <td style=”font-size: 11px; padding:0px 0px 0px 0px” colspan=”2″>                                        

                                                                <xsl:value-of select=”part[@p=’d’]/t”/>





                                                                <td style=”font-size: 11px; padding:0px 0px 0px 0px”>Min:

                                                                <xsl:value-of select=”low”></xsl:value-of>C </td>

                                                                <td style=”font-size: 11px; padding:0px 0px 0px 0px” >Max:

                                                                <xsl:value-of select=”hi”></xsl:value-of>C </td>






Posted in WebParts, XSLT | Leave a Comment »

Customizing Content Query Webpart

Posted by Jessica Wang on March 3, 2008


Firstly, Heather Solomon has an excellent article on it.

Part 1: Export Content Query Web part

Open it up and search for CommonViewFields

Add in Fields that you want; you will need to use the internal name and the type of data.

A good tool is Sharepoint Explorer for WSS 

<property name=”CommonViewFields” type=”string”>InternalName, DateField</property>

Example: Calendar Properties 

<property name=”CommonViewFields” type=”string”>EventDate,DateTime; Description,Note; Location,Text; Property_x0020_Unit,Choice</property>

Save the Web Part and Import it back 

Part 2: Locate ItemStyle.xsl under XSL Style Sheet

Create your own custom Item Style 

<xsl:template name=”CustomStyle” match=”Row[@Style=’CustomStyle’]” mode=”itemstyle”>  <xsl:variable name=”SafeImageUrl”>
            <xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”>
                <xsl:with-param name=”UrlColumnName” select=”‘ImageUrl'”/>
  <xsl:variable name=”SafeLinkUrl”>
            <xsl:call-template name=”OuterTemplate.GetSafeLink”>
                <xsl:with-param name=”UrlColumnName” select=”‘LinkUrl'”/>
  <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:variable name=”LinkTarget”>
            <xsl:if test=”@OpenInNewWindow = ‘True'” >_blank</xsl:if>
    <td style=”width: 200px”>          
  <xsl:value-of select=”ddwrt:FormatDate(string(@EventDate),3081, 3)”/></td>
    <td valign=”top” rowspan=”3″>|</td>    <td class=”linkitem” style=”width: 200px”>      
    <xsl:call-template name=”OuterTemplate.CallPresenceStatusIconTemplate”/>
                <a href=”{$SafeLinkUrl}” mce_href=”{$SafeLinkUrl}” target=”{$LinkTarget}” title=”mailto:%7B@LinkToolTip}”>
                    <xsl:value-of select=”$DisplayTitle”/>
    <td rowspan=”3″ align=”left”>    
    <xsl:value-of select=”ddwrt:FormatDate(string(@EventDate),3081, 4)”/></td>
    <td>Location: <xsl:value-of select=”@Location”/></td>
    <td >PropertyUnit: <xsl:value-of select=”@Property_x005F_x0020_Unit “/>
    <td> xsl:value-of select=”@Description” disable-output-escaping=”yes”/></td>
    </table>To see what fields are being passed in<xsl:for-each select=”@*”>
    P:<xsl:value-of select=”name()” />

If you want to format the Date Time using ddwrt, remember to add   xmlns:ddwrt=”” within the <xsl:stylesheet> tag.

Posted in WebParts | Leave a Comment »