Search This Blog

Wednesday, 5 December 2007

CAML (Collaborative Application Markup Language) Query syntax in SharePoint

SPQuery is the SharePoint object which is used to perform a query operation against SharePoint data.
SPList.getItems(SPQuery) is the step, will return SPListItemCollection which satisfies the query.
SPQuery has one data member ‘Query’, which need to set before passing SPQuery object to SPList.
Example : SPQuery.
SPQuery objQuery = new SPQuery();
SPQuery.Query=”<Where><Eq><FieldRef Name ='File_x0020_Type'/><Value Type ='Text'>par</Value></Eq></Where>” ;
SPListItemCollection Obj = SPList.getItems(SPQuery);
Comparison Operators, Logical Joins and Order/ Group Operators, plays an important role to make this syntax.
Comparison Operator
Comparison Operators
General Meaning
Eq
=
Gt
>
Lt
<
Geq
>=
Leq
<=
Neq
<>
Contains
Like
IsNull
Null
IsNotNull
NotNull
BeginsWith
Beginning with word
DateRangesOverlap
compare the dates in a recurring event with a specified DateTime value, to determine whether they overlap
Example: DateRangesOverlap
<Where>
<DateRangesOverlap>
<FieldRef Name="EventDate"></FieldRef>
<FieldRef Name="EndDate"></FieldRef>
<FieldRef Name="RecurrenceID"></FieldRef>
<Value Type="DateTime">
<Now/>
</Value>
</DateRangesOverlap>
</Where>
Logical Joins:
Logical Joins
Comments
And
Used within the ‘Where’ element to group filters in a query for a view
Or
Used within the ‘Where’ element to group filters in a query for a view
Example: And
<Where>
<And>
<Neq>
<FieldRef Name="Status"></FieldRef>
<Value Type="Text">Completed</Value>
</Neq>
<IsNull>
<FieldRef Name="Sent"></FieldRef>
</IsNull>
</And>
</Where>
Order/Group Operators:
Order/Group Operators
Comments
OrderBy
Determines the sort order for a query. The OrderBy element contains a group of FieldRef elements
GroupBy
Contains a Group By section for grouping the data returned through a query in a list view

Example: OrderBy
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
</OrderBy>
<Where>
<Or>
<Neq>
<FieldRef Name="Status"></FieldRef>
<Value Type="Text">Completed</Value>
</Neq>
<IsNull>
<FieldRef Name="Status"></FieldRef>
</IsNull>
</Or>
</Where>
Example: GroupBy
<GroupBy>
<FieldRef Name="Modified"/>
</GroupBy>
<Where>
<Or>
<Neq>
<FieldRef Name="Status"></FieldRef>
<Value Type="Text">Completed</Value>
</Neq>
<IsNull>
<FieldRef Name="Status"></FieldRef>
</IsNull>
</Or>
</Where>

Sharepoint Books

Free Download

Sharepoint Free Books Download Here

Thursday, 27 September 2007

Developing Web Part using Web User Control.


Overview

This article gives quick steps for developing web part using web user control (ASCX). Web user controls are designed and developed in web application. Web user control can be loaded into web part, and hence web part development time can be saved by using web user control.

Applies To
Windows SharePoint services
Windows SharePoint Portal Server

Steps
1] Create User Control (ASCX) in web application

2] Create Web Part Project

  • Open .NET IDE 2005
  • Create new project of type ‘Web Part’.


3] Load User Control in Web Part Project.

  • Declare variable _innetcontrol of type Control
  • Declare variable strerror of type String
  • In Render method write the statement

_innercontrol.RenderControl(writer);

  • Write method definition for CreateChildControls

protected override void CreateChildControls()

  • Write body for CreateChildControls

this.Controls.Clear ();

innercontrol = this.Page.LoadControl("\\_layouts\\ADVS.ascx");

this.Controls.Add (_innercontrol);


4] Deploy Web Part


Sample code :

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace UserControl{
[Guid("6f4ba08b-ee02-42d1-af84-bd6467b18509")]
public class UserControl : System.Web.UI.WebControls.WebParts.WebPart{
//Variables
Control _innercontrol;
String strerror;

public UserControl(){
this.ExportMode = WebPartExportMode.All;
}

protected override void Render(HtmlTextWriter writer){
try{
_innercontrol.RenderControl(writer);
}
catch (Exception e){
writer.Write(e.Message + " : " + strerror);
}
}

protected override void CreateChildControls(){
base.CreateChildControls();
try{
this.Controls.Clear();
_innercontrol = this.Page.LoadControl("\\_layouts\\ADVS.ascx");
this.Controls.Add(_innercontrol);
}
catch (Exception e){
strerror = e.Message;
}
}
}
}

Output