Wednesday, June 29, 2011

Microsoft Community Contributor Award

Received my Microsoft Community Contributor award for my contributions to Microsoft online technical communities this morning.



Thanks to Microsoft Community and online support team for recognizing community contributors.

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); 

Sunday, June 5, 2011

CrossListQueryInfo and CrossListQueryCache gotchas

CrossListQueryInfo class which comes with the Microsoft Publishing infrastructure makes use of object caching techniques to query the requested data from the cache instead from the database. Remember to use this facility only if your code runs against a MOSS server and not on a WSS server. As this makes use of  object cache stored in WFE servers, it avoids to database input/output and network latency between the WFE's and database server.

Although it uses SPSiteDataQuery internally,the very first request using CrossListQueryCache takes more time than SPSiteDataQuery. Practically it includes the time for querying, caching and returning the values. But subsequent queries fetch results in a flash and no where comparable with SPSiteDataQuery.

Interesting fact is that this CrossListQueryCache and QueryInfo will not work in a Console line tool, it badly depends on the context. If you are really trying this interesting query technique in a web part, whenever you implement any change in your webpart and trying to debug. Apart from doing the IISReset/App pool recycle, don't forget to flush the object cache

A sample CrossListQueryCache
public DataTable GetDataTableUsingCrosslistQuery(SPSite site)
{
CrossListQueryInfo clquery = new CrossListQueryInfo();
clquery.RowLimit = 100;
clquery.WebUrl = site.ServerRelativeUrl;
clquery.UseCache = true ;
clquery.Lists = "";
clquery.Webs = "";
//clquery.Query = "";
clquery.Query = "569";
clquery.ViewFields = "";
CrossListQueryCache cache = new CrossListQueryCache(clquery);
DataTable results = cache.GetSiteData(site);
return results; 
}