Thursday, December 11, 2008

Web Part Lifecycle

Following is the series of events which occurs for every web part on the page.

1. protected override void OnInit(EventArgs e)
2. protected override void OnLoad(EventArgs e)
3. protected override void CreateChildControls()
4. protected override void LoadViewState(object savedState) //Only at Postback
5. protected override void OnPreRender(EventArgs e)
6. protected override void Render(System.Web.UI.HtmlTextWriter writer)
7. protected override void OnUnload(EventArgs e)
8. public override void Dispose()

Calculated Columns

This blog post is an addition to the knowledge served under the technology domain in my blog. Going specifically into MOSS 2007, which has been the source of my bread and butter (no wonder I've gained weight :)), there is a feature in this product called as MOSS 2007. All people associated with the technology know deep into how to deploy the site column through features, how to create a new site column, types of site columns. What I thought people would love to know is that there is a feature called as calculated site columns in MOSS 2007. The formulas mentioned below can be used in MS EXCEL as well in case you are not a MOSS buff :).

The real mantra here is that there are site columns that need the currently logged in user name or the current date at times. The way to do these is to use the [Me] and [Today] objects. There is a further flaw in this approach. Directly entering this value in the visual code editor for the column value will throw an error. For this first create a column as Me in the content type and use that in the formula. Delete Me after the calculated column has been created to achieve the desired result. The same applies to Today object as well. Happy developing from here on :).

  • How to deploy these calculated columns through features:

It is not very easy to find a sample of how to define a site column of type calculated using the SharePoint 2007 features framework. The documentations shows how to do it using the user interface (see Calculate data in lists or libraries ). The documentation in the WSS SDK about the  Formula Element in the CAML Core Schemas points in the right direction but is maybe not clear enough. I tested the sample code below by using the site columns in a list definition. You might want to test it out in a content type as well - please provide feedback in the comments.

Code sample feature.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Scope="Site" Title="Calculated Sitecolumn" Id="49C90DCA-6C76-4b30-99DB-7C4C7D100761">
<ElementManifests>
<ElementManifest Location="calcsitecolumn.xml"/>
</ElementManifests>
</Feature>

Code sample calcsitecolumn.xml

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field Name="CalcDemo" StaticName="CalcDemo"  Type="Calculated" DisplayName="Calculated column" ID="{DD01AF0E-5E58-4e50-B3E8-1BFC866CA9A0}" ResultType="DateTime" Format="DateOnly" ReadOnly="TRUE">
<Formula>=StartDate+7</Formula>
<Default></Default>
<FieldRefs>
<FieldRef Name="StartDate" ID="{64cd368d-2f95-4bfc-a1f9-8d4324ecb007}" />
</FieldRefs>
</Field>
</Elements>
  • How to use the formulas in the site column (Its basically simple VB code):

You can use the following examples in calculated columns. Examples that do not include column references can be used to specify the default value of a column. For details on how to use these formulas refer to: http://office.microsoft.com/en-us/sharepointtechnology/HA011609471033.aspx

Monday, December 8, 2008

Christmas

This is the exact time uncle Pumblechook got Joe a bottle of port wine and commented on pip being a totally ungrateful boy. He said that pip should be grateful to his aunt for bringing him up so well. The reason i mention this is to hyperlink the fact that many people in so many lives try to help but end up hurting people in turn. This is the perfect time to say the wonderful word to your peers and relatives that might have been hurt sometime. This is the season of perpetual hope. The season people find their true love. The season when people share secrets that are really close to their hearts. This is the season when people get time out of their busy lives to live freely and enjoy with family and friends.

Sitting under the mistletoe,
Bells ringing overhead.
They think of Santa,
and the angels singing overhead.
The sledge of hope is there in the minds,
be the person old or young sleeping in a bed.

Opening presants has been everyones twinkle in the eye moment on this day, since ages that I have seen. Every year there is so much excitement all around.. the christmas carols, the bells, the smiles on peoples faces, the christmas discounts, and a whole lot of goodwill everywhere.
Children love it immensly when you wish them a merry christmas. And since every great man has said there is a child in all of us, do not forget wishing your friends and family "FELIZ NAVIDAD y PROSPERO AÑO FELICIANO"