Code Samples

How to add a manager for a user in Active directory using Infopath web forms

One creating a new user in Active Directory (AD), you might want to add or assign  a manager to the user.  Below is the function to add a manager to the user using infopath web forms

Public Sub AddManager(ByVal dEntry As DirectoryEntry, ByVal ManagerAccount As String, ByVal loginname As String)
            Try
                Dim ManagerSAM As String = ManagerAccount
                Dim ManagerSearcher As New DirectorySearcher()
                ManagerSearcher.PageSize = 10
                ManagerSearcher.Filter = “(&(objectCategory=user) (samAccountName=” & ManagerAccount & “))”
                ManagerSearcher.PropertiesToLoad.Add(“DistinguishedName”)
                ManagerSearcher.SearchScope = SearchScope.Subtree

                Dim managerResult As SearchResult
                Dim ManagerResultCol As SearchResultCollection = ManagerSearcher.FindAll()
                If ManagerResultCol Is Nothing Then
                Else
                    managerResult = ManagerResultCol(0)
                    Dim ManagerName As String = String.Format(managerResult.Properties(“DistinguishedName”)(0))
                    SetADProperty(dEntry, “Manager”, ManagerName)
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message, “Active Directory Error”, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            End Try
        End Sub

1 comment - What do you think?  Posted by Tosh - November 21, 2011 at 9:50 am

Categories: Administration, Code Samples, Infopath   Tags: , ,

SharePoint Custom List Grouping BY Month Name and Year from Date Column

This article explains the process of grouping a Sharepoint list based on Month name and year from a date column.

SharePoint custom list can be grouped on any column from the list. Although you can group by Created (system column in SharePoint list) column but we had to group a list based on the Month Name and year from a Created column (or you can do this on any date column from the list)

Solution:

1.       Create a new column – select colunm type as Calculated Column
2.       In the formula box for the calculated column use the TEXT function to extract the month name from the date column. Below is the syntax for TEXT function:

          - TEXT(ColumnName,format)
          – For full month name use “MMMM” or use “MMM” for 3 letter month names. For example
          Text([Crteaed], “MMMM”) will return March whereas Text([Created], “MMM”) will return Mar
3.       Now we use the YEAR function to get the year from the date column.
4.       Complete Formula will be like this:
          =TEXT([Created],”MMM”)&” “&YEAR([Created])

5.       New calulcated column will now display month name and year as Mar 2010
 
6.       Now create a new view
7. Select Group By option and group it by the newly created calculated column.
8. That’s it

4 comments - What do you think?  Posted by Tosh - September 21, 2010 at 10:44 am

Categories: Administration, Code Samples   Tags: , ,

Creating Calculated Columns using [Today] or [Me]

Calculated columns does not allow you to use [Today] or [Me] in the formula box. So how do we actually get the current date.

The solution I am going to provide is not 100% full proof, but it is a workaround for the problem.

1. Create a column called ‘Today’ in the list
2. It can be of any type – text, date etc.
3. In your calculated Column use [Today] as if you are using a SharePoint function
4. Now go and delete the Column called ‘Today’ which you created before.

Doing the above system, you are kind of fooling SharePoint and the calculated column you defined before will now reference to the Share Point [Today] function.

Problems you might see:

Calculated Column you created before might display you 30/12/1899 as the current date, but if you go back to the calculated column and hit ‘Ok’ again it should display the current date.

This is just a work around to the problem, if you wish to use [Today] in calculated columns.

Same steps goes for [Me] function as well.

You might use [Today] in calculated column like this:

=IF(AND([Due Date]< [CurrentDate], [Status]=”In progress”),”Overdue”, “None”)

Be the first to comment - What do you think?  Posted by Tosh - August 5, 2010 at 3:44 pm

Categories: Administration, Code Samples, Sharepoint Errors   Tags: , ,

Next Page »