Wednesday, April 8, 2009

Improve Sharepoint Site Performance using Blogcache

When a SharePoint is application is created, a web.config file is created in the application folder you specified. One of the entries inside the SharePoint element is BlobCache. By default, it looks like this:

<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" enabled="false" />

In order to improve the performance of your site, the BlobCache should be enabled.

<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" enabled="true" />

The maxSize attribute is in GigaBytes, so make sure you have enough room at the location.


See this article for more information about other caching techniques: http://blogs.msdn.com/ecm/archive/2006/11/08/how-to-make-your-moss-2007-web-site-faster-with-caching.aspx

Store Metadata in Property Bag for SPWEB

Property bags are a new feature of Windows SharePoint Services 3.0. A property bag enables you, as a developer, to add properties to objects in a Windows SharePoint Services site. Property bags are implemented by Windows SharePoint Services as a simple hash table of property names and values.

Many Windows SharePoint Services objects expose property bags, including:

SPWeb
SPFolder
SPFile
SPListItem

You can create and remove properties in a property bag programmatically, and you can modify the values assigned to properties. After updating a property in a property bag, you must invoke the Update() method so that the property value is persisted in the site database.

The following example shows code for adding a property to the property bag of an SPWeb object. The code also shows how to iterate through the property bag to retrieve key names and values.
Visual C# Code Example

// Obtain a reference to the current Web
SPWeb list = SPControl.GetContextWeb(Context);
// Enable updates to be made to the SPWeb object
list .AllowUnsafeUpdates = true;
// Add a property and update the property bag
list .Properties.Add("Project", "Development");
list .Properties.Update();
// Disable updates for the SPWeb object
list .AllowUnsafeUpdates = false;
// Iterate through the properties in the property bag
for each(System.Collections.DictionaryEntry webProperty
in
list .Properties)
{
this.Page.Response.Write(webProperty.Key.ToString()
+ " : "
+ webProperty.Value.ToString()
+ "
");
}


Once my metadata are added to my SPWeb properties, it's impossible to remove them.

Here is my code to delete :

site.Properties.Remove("mykey");

site.Properties.Update();

site.Update();

Tuesday, April 7, 2009

Bind List Items using SPDataSource using the object model

SPDataSource is a control that can be used to access data without needing declarative code


<%@ Register Tagprefix="SPwebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


<SPWebControls:SPDataSource runat="server" ID="dsPersonTitles" DataSourceMode="List"
SelectCommand="<Query><OrderBy><FieldRef Name='FirstName' /></OrderBy></Query>"

>

<SelectParameters>
<asp:Parameter Name="WebUrl" DefaultValue="{sitecollectionroot}" />
<asp:Parameter Name="ListName" DefaultValue="Employee" />
</SelectParameters>
</SPWebControls:SPDataSource>

<asp:DropDownList runat="server" ID="ddlPersonTitles" CssClass="title" DataSourceID="dsPersonTitles" DataTextField="FirstName" DataValueField="ID">
</asp:DropDownList>



Parameters

The SPDataSource Inherits from SPDataSourceView, basically a helper class for SPDataSourceView.
After a little Reflector-ing of SPDataSourceView I found these keys it is processing from from the parameter values collection.

  • webid
  • weburl
  • rootfolder
  • listid
  • listname
  • listitemguid
  • listitemid
  • folderid
  • nextpagedata
  • startrowindex
  • maximumrows