Fill...">

Get list of headers from xml files

I am trying to get headers of xml files from the "bugs" folder.

My code:

    public virtual List<IBug> FillBugs()
    {
        string folder = xmlStorageLocation + "bugs" + Path.DirectorySeparatorChar;

        List<IBug> bugs = new List<IBug>();

        foreach (string file in Directory.GetFiles(folder, "*.xml", SearchOption.TopDirectoryOnly))
        {
            var q = from b in bugs
                    select new IBug
                    {
                        Title = b.Title,
                        Id = b.Id,
                    };

            return q.ToList();
        }

        return bugs;
    }

      

But I am not getting headers from all xml files in the "bugs" folder.


The biggest problem is getting the eatch files into the singel line, not the [] line.

0


a source to share


4 answers


Your code in writing doesn't make any sense. Perhaps you meant something more:



public virtual List<IBug> FillBugs()
{
    // is this actually correct or did you mix up the concatenation order?
    // either way, I suggest Path.Combine() instead

    string folder = xmlStorageLocation + "bugs" + Path.DirectorySeparatorChar;

    List<IBug> bugs = new List<IBug>();

    foreach (string file in Directory.GetFiles(folder, "*.xml",
        SearchOption.TopDirectoryOnly))
    {
        // i guess IBug is not actually an interface even though it starts 
        // with "I" since you made one in your code

        bugs.Add(new IBug {
            Title = file, Id = 0 /* don't know where you get an ID */ });
    }

    return bugs;
}

      

+2


a source


"out of b in errors" is selected from the empty list. you need to initialize errors from file at the beginning of the foreach loop



+1


a source


Do you need a backslash (Path.DirectorySeparatorChar) between xmlStorageLocation and "errors"?

0


a source


You are not using file

in your ring anywhere - is that correct or did you miss to insert it into the collection?

0


a source







All Articles