"The name does not exist in the current context" - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

"The name does not exist in the current context"

Last post 10-23-2013 11:25 AM by arothacker. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 10-23-2013 11:25 AM

    "The name does not exist in the current context"

    Hello-

     I have code that allows an infopath form to edit items in a sharepoint list. The only problem I'm having is that i get the error: the name "e" does not exist in the current context.

    Here's my code:

    using Microsoft.Office.InfoPath;

    using System;

    using System.Xml;

    using System.Xml.XPath;

    namespace Updated_Headcount

    {

    public partial class FormCode

    {

    // Member variables are not supported in browser-enabled forms.

    // Instead, write and read these values from the FormState

    // dictionary using code such as the following:

    //

    // private object _memberVariable

    // {

    // get

    // {

    // return FormState["_memberVariable"];

    // }

    // set

    // {

    // FormState["_memberVariable"] = value;

    // }

    // }

    // NOTE: The following procedure is required by Microsoft Office InfoPath.

    // It can be modified using Microsoft Office InfoPath.

    public void InternalStartup()

    {

    ((
    ButtonEvent)EventManager.ControlEvents["UpdateList"]).Clicked += new ClickedEventHandler(UpdateList_Clicked("Update", e.Source.CreateNavigator()));

    }

    public void UpdateList_Clicked(string strOperation, XPathNavigator e)

    {

    //Create a new instance of our "Lists" web service

    ServerName.Lists myList = new ServerName.Lists();

    //Pass the logged on users credentials to the web service

    myList.Credentials = System.Net.CredentialCache.DefaultCredentials;

    //Create a DataSource object for our list data source

    DataSource dsContacts = this.DataSources["Updated Headcount"];

    //Create a NamespaceManager object so we can use the various namespaces on our XPATH expressions

    XmlNamespaceManager ns = this.NamespaceManager;

    //Create XPathNavigator objects for each field from our list

    XPathNavigator xnID = e.SelectSingleNode("@ID", ns);

    XPathNavigator xnTitle = e.SelectSingleNode("@Title", ns);

    XPathNavigator xnLastName = e.SelectSingleNode("@LastName ", ns);

    XPathNavigator xnFirstName = e.SelectSingleNode("@FirstName", ns);

    XPathNavigator xnFranchise = e.SelectSingleNode("@Franchise", ns);

    XPathNavigator xnLocation = e.SelectSingleNode("@Location", ns);

    XPathNavigator xnPillar = e.SelectSingleNode("@Pillar", ns);

    XPathNavigator xnLeader = e.SelectSingleNode("@Leader", ns);

    XPathNavigator xnActivity = e.SelectSingleNode("@Activity", ns);

    XPathNavigator xnCategory = e.SelectSingleNode("@Category", ns);

    XPathNavigator xnPosition = e.SelectSingleNode("@Position", ns);

    XPathNavigator xnDeptNumber = e.SelectSingleNode("@DeptNumber", ns);

    XPathNavigator xnSupervisor = e.SelectSingleNode("@Supervisor", ns);

    XPathNavigator xnEmployeeType = e.SelectSingleNode("@EmployeeType", ns);

    XPathNavigator xnFTE = e.SelectSingleNode("@FTE", ns);

    XPathNavigator xnNotes = e.SelectSingleNode("@Notes", ns);

    //Create a new XmlDocument to use for specifying the Update CAML query

    XmlDocument doc = new XmlDocument();

    //Create the needed update element

    System.Xml.XmlElement updates = doc.CreateElement("Batch");

    //Create the CAML query passing in the value of each of our fields from the form

    if (strOperation == "Delete")

    {

    updates.InnerXml =
    string.Format(@"<Method ID='1' Cmd='Delete'>" +"<Field Name='ID'>" + xnID.Value + "</Field>" + "</Method>");

    }

    else

    {

    //Create the CAML query passing in the value of each of our fields from the form

    updates.InnerXml = string.Format(@"<Method ID='1' Cmd='Update'>" +

    "<Field Name='ID'>" + xnID.Value + "</Field>" +

    "<Field Name='Title'>" + xnTitle.Value + "</Field>" +

    "<Field Name='LastName'>" + xnLastName.Value + "</Field>" +

    "<Field Name='FirstName'>" + xnFirstName.Value + "</Field>" +

    "<Field Name='Franchise'>" + xnFranchise.Value + "</Field>" +

    "<Field Name='Location'>" + xnLocation.Value + "</Field>" +

    "<Field Name='Pillar'>" + xnPillar.Value + "</Field>" +

    "<Field Name='Leader'>" + xnLeader.Value + "</Field>" +

    "<Field Name='Activity>" + xnActivity.Value + "</Field>" +

    "<Field Name='Category'>" + xnCategory.Value + "</Field>" +

    "<Field Name='Position>" + xnPosition.Value + "</Field>" +

    "<Field Name='DeptNumber'>" + xnDeptNumber.Value + "</Field>" +

    "<Field Name='Supervisor'>" + xnSupervisor.Value + "</Field>" +

    "<Field Name='EmployeeType'>" + xnEmployeeType.Value + "</Field>" +

    "<Field Name='FTE'>" + xnFTE.Value + "</Field>" +

    "<Field Name='Notes'>" + xnNotes.Value + "</Field>" + "</Method>");

    }

    //Update the list

    XPathNavigator xnListGUID = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:ListName", ns);

    XmlNode node = myList.UpdateListItems(xnListGUID.Value, updates);

    //Requery the data source to reflect the updates

    dsContacts.QueryConnection.Execute();

    }

    }

    }

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