C# 名称为;";在这种情况下不存在。

C# 名称为;";在这种情况下不存在。,c#,infopath-2007,C#,Infopath 2007,我一直在看其他文章试图解决这个问题,但我对在InfoPath中编码真的很陌生。我有一个允许我使用Infopath在SharePoint列表中提取项目的代码。我不断得到一个错误,即“名称“e”在当前上下文中不存在”。请帮忙 public void InternalStartup() { ((ButtonEvent)EventManager.ControlEvents["UpdateList"]).Clicked += new ClickedEventHandler(

我一直在看其他文章试图解决这个问题,但我对在InfoPath中编码真的很陌生。我有一个允许我使用Infopath在SharePoint列表中提取项目的代码。我不断得到一个错误,即“名称“e”在当前上下文中不存在”。请帮忙

    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();      
    }

}
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents[“UpdateList”]).Clicked+=新建ClickedEventHandler(UpdateList_单击(“更新”,e.Source.CreateNavigator());
}
public void UpdateList_已单击(字符串strOperation,XPathE)
{
//创建“列表”web服务的新实例
ServerName.Lists myList=newservername.Lists();
//将登录的用户凭据传递给web服务
myList.Credentials=System.Net.CredentialCache.DefaultCredentials;
//为列表数据源创建数据源对象
DataSource dsContacts=this.DataSources[“更新的员工人数”];
//创建一个NamespaceManager对象,以便我们可以在XPATH表达式上使用各种名称空间
XmlNamespaceManager ns=this.NamespaceManager;
//为列表中的每个字段创建XPathNavigator对象
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);
//创建用于指定更新CAML查询的新XmlDocument
XmlDocument doc=新的XmlDocument();
//创建所需的更新元素
System.Xml.xmlement updates=doc.CreateElement(“批处理”);
//创建CAML查询,从表单中传入每个字段的值
如果(strOperation==“删除”)
{
updates.InnerXml=string.Format(@“”+
“+xnID.Value++”);
}
其他的
{
//创建CAML查询,从表单中传入每个字段的值
updates.InnerXml=string.Format(@“”+
“”+xnID.Value+“”+
“”+xnTile.Value+“”+
“”+xnLastName.Value+“”+
“”+xnFirstName.Value+“”+
“”+xnFranchise.Value+“”+
“”+xnLocation.Value+“”+
“”+xnPillar.Value+“”+
“”+xnLeader.Value+“”+
“”+xnPosition.Value+“”+
“”+xnDeptNumber.Value+“”+
“”+xnSupervisor.Value+“”+
“”+XNEMPloyeType.Value+“”+
“”+xnFTE.Value+“”+
“+xnNotes.Value++”);
}
//更新列表
XPathNavigator xnListGUID=this.MainDataSource.CreateNavigator().SelectSingleNode(“/my:myFields/my:ListName”,ns);
XmlNode node=myList.UpdateListItems(xnListGUID.Value,updates);
//重新查询数据源以反映更新
dsContacts.QueryConnection.Execute();
}
}

}

假设单击的
是一个带有
void(string,XPathNavigator)
签名的事件,您应该这样添加事件处理程序:

public void InternalStartup()
{
    ((ButtonEvent)EventManager.ControlEvents["UpdateList"]).Clicked += UpdateList_Clicked;
}
你是说

public void InternalStartup()
{
    ((ButtonEvent)EventManager.ControlEvents["UpdateList"]).Clicked +=
      (s, e) => UpdateList_Clicked("Update", e.Source.CreateNavigator());
}

您的InternalStartup方法中是否存在错误?它看起来没有定义