expected class, delegate, enum, interface or struct error C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,

Im new to C#. Im getting an "expected class, delegate, enum, interface or struct" error when compling infopath C# code from Microsoft Submitting Data from InfoPath to a SharePoint list  http://msdn.microsoft.com/en-us/library/cc162745.aspx http://msdn.microsoft.com/en-us/library/cc162745.aspx . I pasted the code directy from their site. Can anyone help me out?

Thanks,

Paul

The error ocurrs on first line of the following code:<font color="#0000ff" size=2><font color="#0000ff" size=2>
private</font></font> <font color="#0000ff" size=2><font color="#0000ff" size=2>void</font></font><font size=2> ClearEnteredValues(XPathNavigator xnDoc)
{
</font><font color="#0000ff" size=2><font color="#0000ff" size=2>try</font></font><font size=2>
{
</font><font color="#008000" size=2><font color="#008000" size=2>// Get a reference to the forms XmlNamespaceManager object.</font></font><font size=2>
XmlNamespaceManager ns = </font><font color="#0000ff" size=2><font color="#0000ff" size=2>this</font></font><font size=2>.NamespaceManager;
</font><font color="#008000" size=2><font color="#008000" size=2>// Create an XPathNodeIterator object to get a count of the </font></font><font size=2>
</font><font color="#008000" size=2><font color="#008000" size=2>// rows in the repeating table used to add new Contacts.</font></font><font size=2>
XPathNodeIterator xi = xnDoc.Select(
</font><font color="#a31515" size=2><font color="#a31515" size=2>"/my:myFields/my:gpContacts/my:gpContact"</font></font><font size=2>, ns);
</font><font color="#0000ff" size=2><font color="#0000ff" size=2>int</font></font><font size=2> rowCount = xi.Count;
</font><font color="#0000ff" size=2><font color="#0000ff" size=2>if</font></font><font size=2> (rowCount > 0)
{
</font><font color="#008000" size=2><font color="#008000" size=2>// Get the first and last rows (nodes) in the </font></font><font size=2>
</font><font color="#008000" size=2><font color="#008000" size=2>// repeating table.</font></font><font size=2>
XPathNavigator firstNode = xnDoc.SelectSingleNode(
</font><font color="#a31515" size=2><font color="#a31515" size=2>"/my:myFields/my:gpContacts/my:gpContact[1]"</font></font><font size=2>, ns);
XPathNavigator lastNode = xnDoc.SelectSingleNode(
</font><font color="#a31515" size=2><font color="#a31515" size=2>"/my:myFields/my:gpContacts/my:gpContact["</font></font><font size=2> +
rowCount + </font><font color="#a31515" size=2><font color="#a31515" size=2>"]"</font></font><font size=2>, ns);

</font><font color="#008000" size=2><font color="#008000" size=2>// Delete the existing nodes using the DeleteRange method.</font></font><font size=2>
firstNode.DeleteRange(lastNode);
}
</font><font color="#008000" size=2><font color="#008000" size=2>// Clear the check box. </font></font><font size=2>
xnDoc.SelectSingleNode(
</font><font color="#a31515" size=2><font color="#a31515" size=2>"/my:myFields/my:AddContacts"</font></font><font size=2>, ns).SetValue(</font><font color="#a31515" size=2><font color="#a31515" size=2>"false"</font></font><font size=2>);
}
</font><font color="#0000ff" size=2><font color="#0000ff" size=2>catch</font></font><font size=2> (Exception ex)
{
MessageBox.Show(</font><font color="#a31515" size=2><font color="#a31515" size=2>"The following error occurred: "</font></font><font size=2> +
ex.Message);
</font><font color="#0000ff" size=2><font color="#0000ff" size=2>throw</font></font><font size=2>;
}
}</font>

View the full article
 
Back
Top