SharePoint Tip of the day : Manage default value in your custom field type


I took me quite a long time figure out why my <defaultvalue> property of my custom field type was not taken into account. It turned out that I need to do a little bit of work in my overriding of the CreateChildControls of my field control.
Basically, we are checking the field has actually no value (to avoid overriding a previously set value) through base.ListItemFieldValue and also if a default value was provided in the field xml definition (or programmatically).

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            if(ControlMode== SPControlMode.New || ControlMode == SPControlMode.Edit)
            {
                string currentValue = (base.ListItemFieldValue == null ? string.Empty : base.ListItemFieldValue.ToString());
                if (string.IsNullOrEmpty(
currentValue) && !string.IsNullOrEmpty(Field.DefaultValue))
                {
                    base.ListItemFieldValue = Field.DefaultValue;
                }
            }
        }

Sweet !

SharePoint Tip of the Day : Render a link within a SPGridView


    <SharePointWebControls:SPGridView runat="server" ID="spgridviewApprovalTasks" DataSourceID="dataSourceApprovalTasks" AutoGenerateColumns="false" EmptyDataText="<p><i>Nothing is waiting for approval.</i></p>">
         <Columns>
             <asp:BoundField HeaderText="Task" DataField="Task" />
             <asp:BoundField HeaderText="Created on" DataField="Created on" />
             <asp:BoundField HeaderText="Description" DataField="Description" HtmlEncode="False" />
             <asp:BoundField HeaderText="Status" DataField="Status" />
             <asp:BoundField HeaderText="Comments" DataField="Comments" />
             <asp:TemplateField HeaderText="Page">
                 <ItemTemplate>
                      <a href='<%#new SPFieldUrlValue(Convert.ToString(Eval("Element To Approve"))).Url%>' style='white-space:nowrap'>&rarr; view the media</a>
                  </ItemTemplate>
             </asp:TemplateField>
         </Columns>
    </SharePointWebControls:SPGridView>

Now I have to remember how to use the field name instead of display name within the SPGridView because it's damn ugly to rely on the display name !

SharePoint Tip of the Day – Programmatically changing a SPWeb navigation settings without relying on the property bag


I used to follow Andre Vala advices to change the navigation settings of a specific SPWeb (cf http://blogit.create.pt/blogs/andrevala/archive/2008/12/06/SharePoint-Tip-_2300_24_3A00_-Changing-a-Web-Site_2700_s-Navigation-Settings.aspx) but recently I found that they can be set in a cleaner way by casting the SPWeb to a PublishingWeb and changing the relevant properties :

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.NavigationOrderingMethod = OrderingMethod.Automatic;
publishingWeb.NavigationAutomaticSortingMethod = AutomaticSortingMethod.CreatedDate;
publishingWeb.NavigationSortAscending = true;
web.AllowUnsafeUpdates = true;
publishingWeb .Update();
web.AllowUnsafeUpdates = false;