Archive for July, 2009

Create SPView programmatically with Group by Option

July 27, 2009 6 comments
You can create a view ( SPView ) with group by option. SPViewCollection add method takes couple of parameters. Most important to explain is View Fields and Query. Both are string variables. in View fields, you can mention  the fields that you want to display in the view. Query contains your where clause, group by clause and order by clause. Query is CAML syntax. Please note order by is rows order while the Columns order is your view fields. It means you should add fields names in order that you want.
        SPList plList=oWeb.Lists["MyList"];

          // create new default view that is grouped
            string viewQuery = @"
                <GroupBy Collapse=""FALSE"" GroupLimit=""100"">
                  <FieldRef Name=""Year"" Ascending=""FALSE"" />
                  <FieldRef Name=""Year"" Ascending=""FALSE"" />
                  <FieldRef Name=""Period"" Ascending=""FALSE"" />
            StringCollection viewFields = new StringCollection();
            plList.Views.Add("Grouped By Year", viewFields, viewQuery, 100, true, true, SPViewCollection.SPViewType.Html, false);

Categories: Sharepoint 2007

Using Different Date Format formula in Calculated Field

July 13, 2009 1 comment
Display DD-MMM-YYYY format
=TEXT(Created,”dd MMM yyyy”)
Display 1st Day of the Month
Some one in the document library was looking for this format based on document creation date. Different project managers submit status reports to their higher manager in a sharepoint document library. Status reports should be displayed in grouping based on creation date of document. Grouping should be on 1st day of that month. so here is the formula that was used in a calculated field and that field was used in grouping.
1st Day of Week (Monday)
=[mydate] – WEEKDAY([mydate], 3) Last Day of Week (Sunday)
=[mydate] – WEEKDAY([mydate], 3) + 6 

Date add year or month

Scenario was that calculate next training screen date for an employee based on most recent training date. If most recent date is any day of November or December, It should be 12.31 of next year otherwise it should be most recent training date + 14 months. Below is simple formula to acheive it in calculated column.

=IF(MONTH([Most Recent Training Date])>=11,DATE(YEAR([Most Recent Training Date])+1,12,31),DATE(YEAR([Most Recent Training Date]),MONTH([Most Recent Training Date])+14,DAY([Most Recent Training Date])))

Categories: Sharepoint 2007

Awarded MVP 2009 for SharePoint 2007

It was 7/1/ 2009.
I was at a customer site and i was just about to leave for my flight. Just an hour before, i got the MVP notification from Microsoft that i have become MVP now. It was very exciting moment for me. One of the happiest day of my life. I got a huge apprecitation from every one. I really felt like a different person. I was very motivated again to do more to help community for SharePoint development. I am an active contributor to SharePoint Development and Programming Forum.
Categories: Uncategorized