error debugging c# class

Status
Not open for further replies.

phoenix108

Wise, Aged Ars Veteran
106
I get the following error in main.aspx concerning the line 'test.load("file");'

Compiler Error Message: CS1519: Invalid token '(' in class, struct, or interface member declaration


*******************************
here is main.aspx:
*******************************
Code:
<!--#include virtual="xml.aspx" -->

<script language="c#" runat=server>

  XmlApp test = new XmlApp("/structure.xml");
  test.load("file");

</script>

********************************
here is my class (xml.aspx)
*******************************
Code:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>

<script language="c#" runat=server>


public class XmlApp {


  XmlDocument document;
  string filePath;
  XmlNode node;

  public XmlApp (string filePath) {
    this.filePath = filePath;
    document = new XmlDocument();
  }

  public void load (string filePath) {
    document.Load(this.filePath);
  }

}

</script>
 

GrimLock

Ars Tribunus Militum
2,189
Subscriptor
filePath was set when creating a new instance of the XmlApp class, the load method uses the filePath member to load. "file" isn't being used at all, which is why I suggested taking it out so it looks cleaner.

I still can't find how a '(' is a bad token anywhere. Since the error comes at 'test.load("file");', maybe the error comes when loading the file in 'document.Load(this.filePath);'? Perhaps there's an error in loading the xml file by relative path. Maybe try 'document.Load(Server.MapPath(this.filePath));'.
 
Status
Not open for further replies.