[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error Reading fixed length file

Posted on 2011-09-08
5
Medium Priority
?
434 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 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