Solved

Error Reading fixed length file

Posted on 2011-09-08
5
420 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 74

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 74

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 74

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes 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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now