I am working on some C# code that returns a cursor response. The cursor does have items in it. I can access them individually. How can I determine a "count" of items, or how do I control an interation loop of the items returned by the cursor? In other words, if I start reading items from the start of a cursor list, what is the best way to detemine the end of the list. Any help on controlling the loop starting at the cursor start through end would be appreciated.


Much of the code below is taken from the VB example in the documentation and converted to C#.

gwws.createCursorRequest gwCreateCursorReq = new gwws.createCursorRequest();
gwws.createCursorResponse gwCreateCursorResp = new gwws.createCursorResponse();
gwws.readCursorRequest gwReadCursorReq = new gwws.readCursorRequest();
gwws.readCursorResponse gwReadCursorResp = new gwws.readCursorResponse();
gwws.destroyCursorRequest gwDestroyCursorReq = new gwws.destroyCursorRequest();
gwws.destroyCursorResponse gwDestroyCursorResp = new gwws.destroyCursorResponse();
gwws.Filter gwFilter = new gwws.Filter();
gwws.FilterGroup gwFilterGroup = new gwws.FilterGroup();
gwws.FilterEntry[] gwfe = new gwws.FilterEntry[3];

string subject;
string location;
string edate;
string sdate;
string gwView;

// Filter for Appointment
gwfe[0] = new gwws.FilterEntry();
gwfe[0].op = gwws.FilterOp.eq;
gwfe[0].field = "@type";
gwfe[0].value = "Appointment";

// Filter for Date Range
gwfe[1] = new gwws.FilterEntry();
gwfe[1].op = gwws.FilterOp.gte;
gwfe[1].field = "startDate";
gwfe[1].value = "2012-01-01T00:00:00Z";

gwfe[2] = new gwws.FilterEntry();
gwfe[2].op = gwws.FilterOp.lte;
gwfe[2].field = "startDate";
gwfe[2].value = "2012-02-29T00:00:00Z";

// Use Filter
gwFilterGroup.op = gwws.FilterOp.and;
gwFilterGroup.element = gwfe;
gwFilter.element = gwFilterGroup;

gwView = "default peek id container @type message recipients attachments subject location startdate enddate place";
gwCreateCursorReq.view = gwView;

gwCreateCursorReq.container = "folders";
gwCreateCursorReq.filter = gwFilter;

gwCreateCursorResp = ws.createCursorRequest(gwCreateCursorReq);

if (gwCreateCursorResp.status.code != 0 || gwCreateCursorResp.cursorSpecified == false)
{
{
ofl.WriteLine("Problem creating cursor for: " );
}
}
// Read the items in the container
gwReadCursorReq.cursor = gwCreateCursorResp.cursor;
gwReadCursorReq.position = gwws.CursorSeek.start;
gwReadCursorReq.forward = true;
gwReadCursorReq.container = "folders";
gwReadCursorReq.count = 10;
gwReadCursorResp = ws.readCursorRequest(gwReadCursorReq);

int i = 1;
while ((gwReadCursorResp.items != null)) && (gwReadCursorReq.count > 0) && (gwReadCursorResp.status.code == 0))
{
gwReadCursorReq.position = gwws.CursorSeek.current;
gwReadCursorResp = ws.readCursorRequest(gwReadCursorReq);

if (gwReadCursorResp.status.code == 0)
{
{
gwws.Appointment c = (gwws.Appointment)gwReadCursorResp.items.item[i];
subject = c.subject;
sdate = c.startDate.ToString();
edate = c.endDate.ToString();
location = c.place;
ofl.WriteLine(subject + "," + location + "," + sdate + "," + edate + "," + gwReadCursorResp.status.code);
i++;
}
}
else
{
ofl.WriteLine("Cursor Status Problem" + " " + gwReadCursorResp.status.code);
}

}

MessageBox.Show("Appointments cCount " + gwReadCursorResp.items.count.ToString());

//' Make sure you destoy the cursors. The data in the cursor can go stale.
if (gwCreateCursorResp.cursorSpecified == true)
{
gwDestroyCursorReq.cursor = gwCreateCursorResp.cursor;
gwDestroyCursorResp = ws.destroyCursorRequest(gwDestroyCursorReq);
if (gwDestroyCursorResp.status.code != 0 )
{
MessageBox.Show("Problem destroying cursor for: " );
}
}

}