I highly recommend that you use foreach rather a for index when iterating
collections in SharePoint. In a for index loop, every request results in a call
to the database to retrieve that one listitem, whereas in a foreach loop, the
first request causes the API to retrieve the listitems into memory with a single
database call and each iteration simply retrieves the next listitem from that
cache.
So, this code:
for (int i = 0; i < items; i++)
{
ddlReports.Items.Add(ReportLibrary.Items[i].DisplayName.ToString());
}
would look like this:
foreach (SPListItem item in ReportLibrary.Items)
{
ddlReports.Items.Add(item.DisplayName.ToString());
}
I typically even go a step further:
SPListItemCollection items = ReportLibrary.Items;
foreach (SPListItem item in items)
{
ddlReports.Items.Add(item.DisplayName.ToString());
}
IMO, foreach is also more readable.
Finally, be aware that if anyone changes the display name for the "My Reports"
library, the code will break. It is better to either: 1) iterate the collection
of lists to find the one you are looking for with a break when it is encountered
OR 2) use a try catch block (bad WSS API, I know) to retrieve the list or exit
the code block.