Tuesday, November 27, 2007

Public Property Objects in .Net 2.0/Sharepoint Web Parts (Other than string, bool, int &enum)

I were working on a Custom Web Part for a customer, when I came to the point where I needed to save custom properties in a Web Part, besides the more common ones like string, bool, int and enum.

Theese properties was not to be exposed to the user in the property-pane, but merely to be saved for other purposes.

In my case I needed to save values to an ArrayList and/or a HashTable.

The trick is to define the property as follows:

private ArrayList _myProperties = new ArrayList();

[WebBrowsable(false), Personalizable(true)]

public ArrayList MyProperties
        {
            get
            {
                return this._myProperties;
            }
            set
            {
                this._myProperties = value;
            }
        }

When this is done, you can simply save values to the object from your custom EditorPart (ToolPart), and access it from the Host Web Part.

SharePoint CAML - filtering on DateTime WITH TimeValue. Finally a solution...

After searching the Internet for quite long now, I've finally managed to locate a solution to executing SPQuery in SharePoint (CAML), by filtering on the TimeValue in DateTime columns.

There have not been any (good) documentation on CAML Queries or SPQuery in the SharePoint SDK.

My temporary solution was to retrieve a larger collection based on the Date-value in DateTime, and then filter on Time-value manually. The code was quite ugly and time-consuming....

Well, as mentioned, there is now a solution to the problem:

The key is to include the following property/parameter in the DateTime tag in the CAML query: IncludeTimeValue="True"

<Value Type=”DateTime” IncludeTimeValue=”TRUE”><Today /></Value>
Creds goes to ucsharp, for posting this in his blog

Business Card