Saturday, January 3, 2009

CAML(Collaborative Application Markup Language)

CAML is just like XML but it is Used as SQL Query for Sharepoint Lists ( list is like a grid view of asp.net but with much more rich functionality in which sharepoint stores its data ).With CAML one can perform SQL Quries to fetch out data from Sharepoint Lists.

Syntax:

<Query><Where><!--Comparison Operators here--><Eq><FieldRef Name=”insertFieldNameHere” /><Value Type=”insertDataTypeHere”>insertValueHere</Value></Eq></Where><OrderBy><FieldRef Name=”insertFieldNameHere” /><FieldRef Name=”insertFieldNameHere” /></OrderBy></Query>

Example :

Simple Sql Query

Select EmployeeName from Employes Where Salary < 3000

CAML :

<Query><OrderBy><FieldRef Name=”EmployeeName” /></OrderBy><Where><Lt><FieldRef Name=”Salary” /><Value Type=”INT”>3000</Value></Lt></Where></Query>

Here in above example we are not using any Table name because we will apply this query on List of Sharepoint like :

It is console programe for C#.net , but you must have WSS 3.0 installed.

class Program
{
static void Main(string[] args)
{
string siteUrl = args[0];
string listName = args[1];
string viewName = args[2];
SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();
SPList employeesList = web.Lists[listName];
SPQuery query = new SPQuery(employeesList.Views[viewName]);
System.Diagnostics.Debug.WriteLine(query.ViewXml);
Console.WriteLine(query.ViewXml);
Console.ReadLine();
}
}

Thursday, January 1, 2009

How to Work on web part with out Sql Server Express

To work with web parts if you dont have sql server express or you want to point your webparts settings to some other database then configure your web.config file.

Step1# Define Connection String that points to your database.
Step2# Define ConnectionStringName property of Defualt provider to your Connection String defined in step#1
step#3 If web parts are not working or throwing exception of Schema then use aspnet_regsql.exe to create schema(Tables and stored Procedures) by Asp.net so that data used for webparts is retrived and saved again in your define database.

Enjoy ;)

web.config --- Code
<appSettings/> <connectionStrings> <add name="LocalSqlServer1" connectionString="Data Source=server;Initial Catalog=database_rahim;User ID=rahim;Password=test/> </connectionStrings> <system.web> <webParts> <personalization defaultProvider="SqlPeronalizationProvider"> <providers> <add name="SqlPeronalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" connectionStringName="LocalSqlServer1" /> </providers> </personalization> </webParts>