Archive for the ‘Sharepoint 2007’ Category

Connect data in web parts

March 26, 2010 Leave a comment

Found this article very helpful for examples of data connections between web parts.

Categories: Sharepoint 2007

Bulk Deletion Feature

March 10, 2010 Leave a comment
You can use this sharepoint feature and it will fit in to your existing sharepoint lists/doc libs etc. This works great.

Categories: Sharepoint 2007

SPDiag for SPS 2007

February 17, 2010 Leave a comment
Categories: Sharepoint 2007

Check Null Date and Use Today date in Calculated formula with Nested IF

September 4, 2009 Leave a comment
Scenario is to check a date value if it does not exist then use today date , otherwise use the original date value.
SharePoint does not support TODAY column yet. however there is a workaround and it is not perfect, but it works with workaround
Assuming that you are on a task list. You have Due Date column that you want to use. You also have another column as Target Date that you want to check as well.
Create a column with name "Today" and keep it as date time
Create another column as Calculated column and i am giving it name here as "Task Status". Write following formula in it.
Please note that COUNTA is used to count the number of columns that has values in it. so i used it to check if there is a value. it return zero if there is no value.
Last step is to delete the Today column that you created above.
One draw back is that Today column value does not refresh until the task is updated. You can write a timer job to run once a day to update any column so that calculated column can refresh today value. OR you may just want to create a column of today and update it through timer job every morning.
Categories: Sharepoint 2007

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

Display SPWeb and sub SPWebs in a Tree Control

November 11, 2008 2 comments
I wanted to create a tree view control look in the same way Sharepoint has in "Manage Content and Structure" page. I had a publishing site and my objective was to list all webs and sub webs as tree control and clicking on a tree node should pull pages from publishing web page library. I used the recursive approach to list the SPWebs in tree control. to quick develop and test this code, i created a simple web application in Visual studio, Referenced the Sharepoint dll and designed my simple page. I wrote the following code and placed my ASPX in sharepoint 12 hive Layouts folder and dll in 80/bin folder. This way i was able to run my code quick as a Layout application in Sharepoint 2007. I had 130 sites in total in following structure (5 levels)
Top Level
———–Level 1
—————–Level 1 a
—————————-Level 1 a subweb1
————————————-Level 1 a subweb1_a
—————————-Level 1 a subweb2
—————–Level 2 a
—————–Level 3 a
Displaying just SPwebs in Tree Control worked perfectly and it was displaying tree control in less than 5 seconds. i was thinking i will face performance issue but it was not the case in 130 sites. Below is the code, please note that oSiteTree is the tree control on ASPX page, please add this control and name it oSiteTree if you are just copying and pasting this code.

‘Call this one either in a button click or page load

Dim oSite as SPSite = New SPSite("http://yoursharepointURL&quot;)

Dim oSPWebRoot As SPWeb = oSite.OpenWeb


New TreeNode(" " + oSPWebRoot.Title, oSPWebRoot.ServerRelativeUrl))

FillSubWeb(oSiteTree.Nodes(0), oSite.OpenWeb)

‘Fill Sub Web call

 Private Sub FillSubWeb(ByVal tn As TreeNode, ByVal webSite As SPWeb)
        Dim theweb As SPWeb
        For Each theweb In webSite.Webs
            Dim subTN As TreeNode = New TreeNode("  " + theweb.Title, theweb.ServerRelativeUrl)
            subTN.ImageUrl = "~/_layouts/Images/cat.gif"

            ‘if you need to display doc libraries or list of SPWeb then add your code here to iterate on LISTS of theweb object

            FillSubWeb(subTN, theweb)
End Sub

Categories: Sharepoint 2007