Friday 20 November 2009

You call this Cheat (or cheap) coding or smart coding

c# split string but keep split chars/ parameter


Today I came across a situ that I had to split a string based on ‘-‘ and keep the split char in the array as well.

Ex\ Split A-B-C-D to a string array with A,-,B,-,C,-,D

If I use the String.Split function with ‘-‘, it will only return the A,B,C,D without my split char.

So I decided to google, and I got nice long functions using regular expressions and substrings.

I didn’t want all those code in to do a simple thing like this and I went on cheating with Split function.



Number.Replace("-", ":-:").Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)


so, am I cheating?

SPSiteDataQuery error – too many lists in the query

"The query cannot be completed because the number of lists in the query exceeded the allowable limit"


SPSiteDataQuery.Lists has a “MaxListLimit” parameter where you can specify the number of lists that the specified query should go through.

Queries without MaxListLimit parameter will run around 1000 lists. Some says this is upto 1000, but I manage to run a query with 1300+ lists.
I think this is depending on the amount of free server resource at that given time.

Inorder to overcome this limit, we can set the “MaxListLimit='0'”, and that will search all list in the site collection.

SPSiteDataQuery.Lists = < Lists BaseType='1' MaxListLimit='0'>


Larger site collections will demand more server resources.
We are currently running a virtual machine with 3GB ram and it seems don’t have any issue with 2000+ document libraries and several thousands of documents.

Thursday 19 November 2009

SPList query performance

Just to add some note on the performance difference between the

SPList.Items.GetItemById(ID) – loads the entire set of list items to the memory and select the given item
And
SPList.GetItemById(ID) – just get the given item


We have used the Items.GetItemById in a workflow and failed miserably. It runs for about 5 mins and times out.

When we changed that to the SPList.GetItemById, it ran under 20 sec.

There are some more SPList query improvement methods are available and you can find those just by googling.