pmac38CDS
asked on
Error Reading fixed length file
I am using the following code to read the schema of a fixed length file from an xml settings file. However when I try to compile I get the following error
The type or namespace name 'Field' could not be found (are you missing a using directive or an assembly reference?)
Here is the code
private static List<Field> GetFields()
{
List<Field> fields = new List<Field>();
XmlDocument map = new XmlDocument();
string appPath = System.IO.Path.GetDirector yName(Syst em.Reflect ion.Assemb ly.GetExec utingAssem bly().GetN ame().Code Base);
//Load the mapping file into the XmlDocument
map.Load(appPath + "\\CMDCSImportCSV_Settings .xml");
//Load the field nodes.
XmlNodeList fieldNodes = map.SelectNodes("/FileMap/ Field");
//Loop through the nodes and create a field object
// for each one.
foreach (XmlNode fieldNode in fieldNodes)
{
Field field = new Field();
//Set the field's name
field.Name = fieldNode.Attributes["Name "].Value;
//Set the field's length
field.Length =
Convert.ToInt32(fieldNode. Attributes ["Length"] .Value);
//Set the field's starting position
field.Start =
Convert.ToInt32(fieldNode. Attributes ["Start"]. Value);
//Add the field to the Field list.
fields.Add(field);
}
//Return the fields – this is now our map of how the flat
// file is laid out.
return fields;
}
Any ideas?
Thanks,
Aditya
The type or namespace name 'Field' could not be found (are you missing a using directive or an assembly reference?)
Here is the code
private static List<Field> GetFields()
{
List<Field> fields = new List<Field>();
XmlDocument map = new XmlDocument();
string appPath = System.IO.Path.GetDirector
//Load the mapping file into the XmlDocument
map.Load(appPath + "\\CMDCSImportCSV_Settings
//Load the field nodes.
XmlNodeList fieldNodes = map.SelectNodes("/FileMap/
//Loop through the nodes and create a field object
// for each one.
foreach (XmlNode fieldNode in fieldNodes)
{
Field field = new Field();
//Set the field's name
field.Name = fieldNode.Attributes["Name
//Set the field's length
field.Length =
Convert.ToInt32(fieldNode.
//Set the field's starting position
field.Start =
Convert.ToInt32(fieldNode.
//Add the field to the Field list.
fields.Add(field);
}
//Return the fields – this is now our map of how the flat
// file is laid out.
return fields;
}
Any ideas?
Thanks,
Aditya
Have you defined a class named Field in your project?
ASKER
I have not. Can you please provide a code snippet ?
Thanks,
Aditya
Thanks,
Aditya
Not really... I have no idea what the field class is supposed to represent. Did you copy/paste this code from somewhere? If so, perhaps they have a definition of the Field class.
ASKER
Yes I got this code from the web. The Field class contains three attributes namely Name,Start and Length.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.