Solved

Error Reading fixed length file

Posted on 2011-09-08
5
423 Views
Last Modified: 2013-12-14
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
0
Comment
Question by:pmac38CDS
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36504074
Have you defined a class named Field in your project?
0
 
LVL 1

Author Comment

by:pmac38CDS
ID: 36504124
I have not. Can you please provide a code snippet ?

Thanks,
Aditya
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36504506
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.
0
 
LVL 1

Author Comment

by:pmac38CDS
ID: 36504664
Yes I got this code from the web. The Field class contains three attributes namely Name,Start and Length.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36504880
You need to copy that class into your project. Your error is because the compiler doesn't know what the definition of Field is because it currently does not exist in your project. Add a new code file to your project and paste the definition of Field into it.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question