Working with sharepoint large lists

Please visit this : Samsung Service Galaxy S

In a recent project, I had to get some information from the last sharepoint listitems inserted. I used foreach. Of course it is a bad idea. When the list grew (thousand of listitems)…the program worked as fast as a drunken turtle. Ok… As I was saying the data I needed was from the last x items inserted. So I replaced the foreach with a simple for:
count=10; (the last 10 items inserted)
for (int i = oList.Items.Count – count; i < oList.Items.Count; i++)

I ran the program and saw that the improvement was not what I expected, so I made a testProject to measure the execution time, for the foreach block code and the code above (with the simple for);

DateTime startTime = DateTime.Now;

chunk of code (for or foreach iteration)

DateTime stopTime = DateTime.Now;
TimeSpan duration = stopTime – startTime;

For large lists the foreach statement took forever. The for statement took from 5 to 30 seconds for 4000 list items.
The odd part was that in the for statement as I said before, i iterated through the last 10 items.
So for 10 items I waited some good seconds.
I googled for the truth and I found this interesting article.

So I found out the SPQuery is one of the best ways to work with large lists.

SPQuery query = new SPQuery(oList.Views[0]);
Comm
query.RowLimit = 10;
SPListItemCollection filteredList = oList.GetItems(query);
foreach (SPListItem item in filteredList)
{
Blabla;
}

I ordered the list Descending by their ID so i got the most recent 10 list items.
I measured the execution time. At the first run it took 800 milliseconds for 4000 list items. The next executions took only from 15 to 30 milliseconds.
I would say…it is at least a good improvement;
An easier way to create CAML queries is with U2U CAML Query Builder
I tried to use CAML query to get the max ID directly but I didn`t succeed. If someone reads this…:P and knows how please leave a reply.

Commerce Server 2009
Thank you,
Ing. Msc. Dan Gheorghe

Advertisements

Kill “Not responding” programs in windows with a shortcut.

Please visit this : Samsung Service Galaxy S

As i was stumbling around, i found this article .
You can kill frozen application just with a double click on a shortcut on your desktop.
You must create a new shortcut and in the location bar write : taskkill.exe /f /fi “status eq not responding” .

Commerce Server 2009

How to make index_changed event work for asp.net Gridview

Please visit this : Samsung Service Galaxy S

I have tried to work with indexchanged event of the asp.net gridview. It didn`t even enter the function. After some searching i found solution.
You must add a column to the gridview typeof linkbutton.
In the Command atribute type “Select”

addlinkbutton1

In the RowDataBound event attach the function GridView1_RowDataBound:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

// Get reference to button field in the gridview.
LinkButton _singleClickButton = (LinkButton)e.Row.Cells[0].Controls[0];
string _jsSingle = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "Select$" + e.Row.RowIndex);
e.Row.Style["cursor"] = "hand";
e.Row.Attributes["onclick"] = _jsSingle;

}
}
}

Now you must override the Render function:

protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
ClientScript.RegisterForEventValidation(((LinkButton)row.Cells[0].Controls[0]).UniqueID, "Select$" + row.RowIndex);
}
}

base.Render(writer);
}

After this you can attach the indexChanged function to the gridview indexchanged event and get your row selected index when you click the row.

Commerce Server 2009