Link to home
Start Free TrialLog in
Avatar of pmac38CDS
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.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            //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
Avatar of kaufmed
kaufmed
Flag of United States of America image

Have you defined a class named Field in your project?
Avatar of pmac38CDS
pmac38CDS

ASKER

I have not. Can you please provide a code snippet ?

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.
Yes I got this code from the web. The Field class contains three attributes namely Name,Start and Length.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial