I have an InfoPath form that gets the current users credentials and looks in a custom list to see if they are there. If they are not in the list there are certain fields that are disabled. When I run this on my development server it works. On my local PC it works (I am an admin), however other users get an error 5337. When I look at the logs it a NullRefException. So after some more diagnosing I see that the problem is when I try to access my custom list. Here is my code:
private void OnToggleControls(string CurrentUserName)
{
string UserFromList;
Boolean IsApprover = false;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(http://sharepointserver))//SPContext.Current.Site)
{
using (SPWeb site = siteCollection.OpenWeb())
{
SPList myList = site.Lists["customlist"];
SPListItemCollection itemCollection = myList.Items;
//Get list of all links and add them to the drop down list.
foreach (SPListItem someItem in itemCollection)
{
UserFromList = (string)someItem["Person"];
if (UserFromList.ToLower().Remove(0, 4) == CurrentUserName.ToLower()) IsApprover = true;
}
}
}
});
if (IsApprover)
{
XPathNavigator domNav = this.MainDataSource.CreateNavigator();
XPathNavigator node = null;
node = domNav.SelectSingleNode("/my:myFields/my:isEnabled", NamespaceManager);
node.SetValue("1");
}
}
I created a console app and put this code in it and it was able to access the list just fine. So do I need to do something different to access my custom list?
Also I have the form security set to full trust and is web based.
Thanks for any suggestions