Solved

Error Reading fixed length file

Posted on 2011-09-08
5
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

737 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