Reading Custom List from InfoPath - InfoPath Dev
in

InfoPath Dev

Reading Custom List from InfoPath

Last post 05-28-2010 12:08 PM by tawright. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-28-2010 09:34 AM

    Reading Custom List from InfoPath

    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

  • 05-28-2010 11:58 AM In reply to

    Re: Reading Custom List from InfoPath

    Have you checked the names of the list, item, site, field you are trying to access to? Maybe you made an error when writing them...

     (example : SPList myList = site.Lists["customlist"]; should be SPList myList = site.Lists["CustomList"];)

  • 05-28-2010 12:08 PM In reply to

    Re: Reading Custom List from InfoPath

    No..I copied and pasted this code in a console app and it worked just fine. 

     I did get it to work here is how I did it.

    private void OnToggleControls(string CurrentUserName)

    {

    string UserFromList;

    Boolean IsApprover = false;

    XPathNavigator secDSNav = DataSources["Approvers"].CreateNavigator();

    XPathNodeIterator rows = secDSNav.Select("/dfs:myFields/dfs:dataFields/dfs:Approvers", NamespaceManager);

    while (rows.MoveNext())

    {

    UserFromList = rows.Current.SelectSingleNode(
    "@Person", NamespaceManager).Value;if (UserFromList.ToLower() == CurrentUserName.ToLower()) IsApprover = true;

    }

     

    if (IsApprover)

    {

    SetFields(
    "1");

    }

    }

    private void SetFields(string fieldVal)

    {

    try

    {

    XPathNavigator domNav = this.MainDataSource.CreateNavigator();

    XPathNavigator node = null;

    node = domNav.SelectSingleNode("/my:myFields/my:IsEnabled", NamespaceManager);

    node.SetValue(fieldVal);

    }

    catch (Exception err)

    {

    throw err;

    }

    }

     

    Can't wait until InfoPath 2010 is install here. Hope this helps someone.

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.