I am trying to grab the current list item, which is an infopath form. So far I am connecting to the sharepoint site, opening the list and trying to grab the current item, but I keep getting an index out of range error. Here is my code
SPSite WebApp = new SPSite("http://site/"); SPWeb site = WebApp.OpenWeb(); site.AllowUnsafeUpdates = true; SPList list = Site.Lists.TryGetList("List_Library"); WebApp.AllowUnsafeUpdates = true; SPListItem item = list.Items[list.Items.Count];
My question is how can I grab the current list? This code is located in the code behind for the infopath form and is in the FormEvents_Submit method that is called when the Submit event is fired. I tried moving the code to the bottom of the method to ensure that the form gets submitted first, but was still receiving the out of range error.