Tuesday, June 7, 2011

Querying calendar list by meeting workspace Url

Calendar list doesn't support querying the list by a workspace url making it a daunting task for finding a recurrence meeting workspace URL in Calendar list. U2U CAML editor and SharePoint views are unable to break this nut.

The trick to accomplish is to pass the relative URL for the CAML segment for querying. Following code snippet helps better understanding.

//removing the Server hostname and protocol, eg:- stripping http://Foo from http://Foo/meetingsite
string hostServer = meetingWeb.Site.Protocol + "//" + meetingWeb.Site.HostName +":" + meetingWeb.Site.Port;
searchUrl = searchUrl.Replace(hostServer, string.Empty);
SPQuery qry = new SPQuery();
qry.Query = @"<Where><Eq><FieldRef Name='Workspace' />
 <Value Type='URL'>" + SPEncode.UrlEncodeAsUrl(searchUrl) + "</Value>" +"</Eq></Where>";
qry.ViewFields = @"<FieldRef Name='Title' />
              <FieldRef Name='Location' />
              <FieldRef Name='EventDate' />
              <FieldRef Name='EndDate' />
              <FieldRef Name='fAllDayEvent' />
              <FieldRef Name='fRecurrence' />";
DataTable tbl= list.GetItems(qry); 

No comments: