Friday, May 29, 2009

WinForm tool with DataGridView for SharePoint list item updating

This is a small tool that can preview, update, delete and insert list items in SharePoint lists. If you've had problems with the standard datasheet list view, you can check the video below - this tool overcomes some of the limitations of the datasheet view and allows for easy manipulation of SharePoint list items:




The tool uses a DataGridView control and fills it with the data of a selected SharePoint list.
The data is retrieved as DataTable. Three ways to get a DataTable with SharePoint list data are used - these can be changed using the drop-down control in the toolbar of the tool:
  • SPWeb.GetSiteData(SPSiteDataQuery) - this method returns a DataTable, all columns of which are with type System.String.
  • SPList.GetItems(SPQuery) - to get a SPListItemCollection and then SPListItemCollection.GetDataTable() - the DataTable returned in this case has typed columns for some of the list fields with certain primitive value types - e.g. System.Int32, System.DataTime and System.Double. One drawback here - the lookup-s are unpleasantly trimmed - they contain only the textual part, not the lookup item ID.
  • SPList.GetItems(SPQuery) - to get a SPListItemCollection and then custom method generating a DataTable from the SPListItem-s in the collection - similar to the standard SPListItemCollection.GetDataTable() but with certain modifications - the column for the yes/no field type is typed - System.Boolean, the lookup values are not trimmed, etc (this is the default way of retrieving list data in the tool).
The updated items are saved using SPWeb.ProcessBatchData(string) - if there're errors during the saving you will see the standard red exclamation mark icons in the left-hand margin of the DataGridView next to the items whose update failed.
The copy-paste functionality allows adding multiple new lines at once. The "copy" logic uses the standard copy functionality of the DataGridView and this has several disadvantages. One is that when drop-downs are used for lookup columns (the combo for lookups button is checked) - the "copy" action gets the display value of the column (the lookup text), not the ID, which then cannot be pasted normally - some nasty error message boxes appear, so don't try this at home.
Note also that not all columns that you can choose from the list field picker are updateable - you will get an error message if you try to update such.
The UI is still not that user friendly as one can wish for, but improvements will follow in the future.

1 comment:

  1. Support for WSS web services added - you can check the latest release here http://splistitemeditor.codeplex.com
    Now the tool can be used to edit list items remotely.

    ReplyDelete