Read lines from more than 1 file of different file extensions, extract the data and output to screen

Hi,
I am trying to read data from more than one file at once. The files are different types e.g. one is a text file one is an xml file like so, StudentInformation.txt, CollegeInformation.xml. The files are all stored in one place, in this case on the D drive of
a local computer. I am trying to locate any files in the D drive with a file extension of .txt or of .xml (there may be more than two of these files in the future, so I'm trying to allow for that). Then I want to open all of these files, extract the information
and output all the information in one display window. I want all the information from these two or more files to be displayed together in the display window.
Here is the code so far. It is throwing up errors.
        //Load from txt or xml files
        private void btnLoad_Click(object sender, RoutedEventArgs e)
                IEnumerable<string> fileContents = Directory.EnumerateFiles("D:\\", "*.*", SearchOption.TopDirectoryOnly)
                .Select(x => new FileInfo(x))
                .Where(x => x.Extension == ".xml" || x.Extension == ".txt")
                .Select(file => ParseFile(file));}
                private string ParseFile(FileInfo file)
                    try
                        using (StreamReader sr = new StreamReader(file.FullName))
                            string line;
                            while ((line = sr.ReadLine()) != null)
                                //Logic here to determine if this is the correct file and append accordingly
                                lbDisplay.Items.Add(line);
                            return line;
                    catch (Exception ex)
                        // Let the user know what went wrong
                        MessageBox.Show("The file could not be read: ");
                        MessageBox.Show(ex.Message);
The error it throws up is:
Error 1
'BookList.MainWindow.ParseFile(System.IO.FileInfo)': not all code paths return a value

This is the Small Basic programming language so moving to a C# forum.
But you need all paths to return a value, including if an exception is called and it jumps to the catch, perhaps just:
// Let the user know what went wrong
MessageBox.Show("The file could not be read: ");
MessageBox.Show(ex.Message);
return "";

Similar Messages

  • When I look up the creation date for files on my Macbook I get the date and month in brackets, but not the year.  Why is this and how can I look up the year?

    When I look up the creation date for files on my Macbook (using "get info", or the information window in Iphoto) I get the date and month in brackets, but not the year.  Why is this and how can I look up the year? 

    Does the Date Modified column in a window set to List view show the date correctly, or does it also display it incorrectly?
    To add additional columns to a Finder (folder) window, with that window open and active open the View Options for it. You can do that by pressing Command-J or by selecting View Options from the View menu in the main menubar.

  • How to read icons from more than a single virtual directory.

    Is it possible to define, for my application, more than one directory for searching images and icons ?
    How to ?
    Tks
    Tullio

    Do You mean FORMS_PATH is searched for icons and images ?
    Does it conflicts with default.icons.iconpath in Registry.dat file ?
    Tks
    Tullio

  • Can i transfer photos from my old iphone directly in to "Moments" WITH the date and such WITHOUT USING ICLOUD?

    I had an iPhone 5 and now i iPhone 6. I saved all the photos in a folder on my computer. How can i transfer all these photos in to my moments folder so they will also have a date on them and correspond with the dates on my current phone's photos. I DO NOT WANT TO PUT THEM IN A SEPARATE FOLDER AND I DONT WANT TO USE ICLOUD because i have over 13gigs of photos

    Can you just back-up the old phone to iTunes and restore it from there?

  • How to extract the date and date format from user reponse

    In BOXIR2 WebI, I have one requirement.
    1) My users will change the infoview interface locales as per their geography ( uk, usa, japan, india etc.)
    2) Users will enter/select the date in a date prompt in the locale specified format
    3) Now my requirement is to display the date in "dd-'mon'-yyyy" using the userresponse.
    Please let me know if any one have any workarounds to get the date from any locale and display in the "dd-mon-yyyy" format.

    Hi,
    I think you will have to use the GetLocale() function and base an if off that
    So something like
    To_Date(UserReponse("promptName");if(GetLocale()="en_US";"MM/dd/yyyy";if(GetLocale()="fr_FR";"dd-mm-yyyy";"dd/mm/yyyy")))
    Regards
    Alan

  • Can takes from more than one track be comped at the same time?

    Greetings,
    I know that this question has been asked recently in this forum (http://discussions.apple.com/thread.jspa?messageID=9527542&#9527542), but I don't think that the respondents completely understood the question... Or perhaps I did not understand the suggested solutions to the problem. I will ask the question in a slightly different way...
    Suppose that I record guitar with 2 microphones (a pickup mic, and a room mic). The first microphone is recorded onto track 1, the second microphone is recorded onto track 2. Multiple takes are done in this manner. When it comes time to comp the tracks, how is it done? Can the takes from more than one track be comped together at the same time? I have tried to do this by grouping both tracks together, but it does not work.
    Any suggestions?
    Thank you.

    You had the right idea grouping the tracks together. You must make sure that in the group settings, the box titled "region selection (edit)" is checked. This will allow you to make the same cuts (or in this case, swipes) on all regions in the group.

  • Extract the data from database and send to XI in form of file

    hi,
        I am working on a scenario in which i am to extract thew data from an ODBC database. and send it to Integration Engine using a file adapter. In this case which adapter i should use? If i go for file adapter then how i will extract the data and if i go for JDBCadapter then i can't send the data in the form of file which is my basic requirement.
    Can someone help me out.

    Hi,
    You can Use JDBC Adapter to pull the data from Dbase very well.
    Check this For Refference Use
    PERIODIC SCHEDULING OF DATA BETWEEN ORACLE DB & R/3 SYSTEM
    Regards
    Seshagiri

  • When I try to adjust the date and time of an event by selecting Photos from iPhoto, the year I enter is altered.

    I have images in iPhoto from an older digital camera which did not record the date and time.  In iPhoto, with an event selected, I have tried to adjust the date and time by choosing Photo.  When I adjust the date and check Modify original files, it makes the date much earlier--in centuries.  I now have an event from August 2003 (the date I entered) which reads June 2, 1251 under the event!  When I attempt to correct it, it goes back further in time.  What am I doing wrong?

    (I use iPhoto only to import from my iPhone; I organize all my images, including thousands of RAW files, in folders on a big external drive.)
    Why are you using iPhoto at all? use image capture or drag and drop the photos
    The problem is that the files I am copying are getting stripped of the EXIF metadata
    eliminating iPhoto from your work flow will eliminate one oppertunity to have this happen  For photos in iPhoto it is best to export them rather than drag an drop them - this assures your EXIF and IPTC data is correct and uptodate
    Why would I be able, over many years, to retain EXIF metadata in photos imported from an iPhone--then one day find that the same workflow strips such photos of EXIF data?
    Because exporting is the supported way to "export" photos - I never drag and drop photos out of iPhoto and I never use thrid party programs on the photos in the iPhoto library - try exporting as suggested above and see if that is the solution
    LN

  • Is there a way to remove the date and time from pictures?

    Is there a way to remove the date and time from phoos in iPhoto?

    Are you referring to the Date and Time some cameras put right on the image?  If so there is nothing really good in iPhoto to do this. You could try the Retouch tool and see how that looks but I think you will need something more precise and powerful, like the clone tool in Aperture.
    Also something like PhotoShop or GIMP - The GNU Image Manipulation Program (free) should do what you want also.
    If your asking about some other date post back.
    regards

  • How to load and unload more than one external swf files in different frames?

    I do not have much experience on Adobe Flash or Action Script 3, but I know the basics.
    I am Arabic language teacher, and I design an application to teach Arabic, I just would like to learn how to load and unload more than one external swf files in different frames.
    Thanks

    Look into using the Loader class to load the swf files.  If you want to have it happen in different frames then you can put the code into the different frames.

  • JDBC-XI-FILE scenario. How to extract data from more than one table in JDBC

    Hi,
    I was asked a question like in JDBC-XI-FILE scenario........ How to extract data from more than one tables (i.e from JDBC system) ?? What is the logic to do the same ??
    I am not sure whether this is a valid question..........but any help in this regards is highly appreciated.
    Regards
    Kumar

    HI,
    Yes it can be possible ,please see the following links
    JDBC  Receiver with Oracle Stored Procedures
    configuring jdbc adapter with multiple tables
    RFC -> XI -> JDBC Scenario Updating Multiple Tables
    /people/alessandro.berta/blog/2005/10/04/save-time-with-generalized-jdbc-datatypes
    JDBC Adapter multiple Selects
    https://www.sdn.sap.com/irj/sdn/advancedsearch?query=jdbc%20with%20multiple%20tables&cat=sdn_all
    Regards
    Chilla..

  • Need to download JAR files from more than ONE HTTP-server ?

    Hello,
    We have a need to download JAR files for an application, from more than ONE HTTP-server, i.e. any specified HTTP-server in an extremely secure network.
    Does a solution exist for this requirement ? Is it possible to design a solution our selfes for this problem ?
    Best Regards
    Peter

    We have a need to download JAR files for an
    application, from more than ONE
    HTTP-server, That can be done using the extension element
    from within the resources element of the main JNLP.
    http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html#resources
    The extension element should refer to another JNLP
    (on the other site) that refers to the Jars. The jar files
    in any such (foreign) JNLP need to be signed, and the
    JNLP files should declare itself as a <component-desc>.
    For any level of detail on using extensions/components,
    download the spec. mentioned in the second paragraph
    of that section linked above. Unfortunately I can find no
    web browsable form of the information.
    Here is an example though..
    http://www.javasaver.com/testjs/jws/04/glclock.jnlp
    This (sandboxed) screenaver demo comes off my
    javasaver site. It refers to the JOGL API via an
    extension element in the JNLP, that points directly
    to the JOGL site. You might notice the security
    warning that is produced mentions..
    Name:      JOGL
    Publisher: sun microsystems, inc
    Source:    https://jogl.dev.java.net
    ..i.e. any specified HTTP-server in an
    extremely secure network. I do not know about an extremely secure network,
    but if it is OK to launch a normal JNLP for an
    application with a 'main()' from the server, I guess
    it should be OK to launch extensions off it - you
    might need to set up some tests.

  • How to read contents of more than 2 files.

    hi all
    help me.
    How to read contents of more than 2 files.
    For reading a file contents we uses normally FileInputStream
    For reading two file contents we uses normally SequenceInputStream
    But which class we have to use for reading contents of more than 2 files at a time
    thanks in advance.

    SequenceInputStream can be used for reading any number of input streams (not at once, but one after the other).
    This involves making an Enumeration that returns the input streams you want to read. Depending on what you want to do, it might be just as easy to read them one after another.
    Or consider making a Vector of your input streams and using its elements() method. Like this:(untested)Vector<InputStream> inVec = new Vector<InputStream>();
    inVec.add(new FileInputStream("foo.dat"));
    inVec.add(new FileInputStream("bar.dat"));
    inVec.add(new FileInputStream("baz.dat"));
    // later...
    SequenceInputStream in = new SequenceInputStream(inVec.elements());

  • Read lines from text file to java prog

    how can I read lines from input file to java prog ?
    I need to read from input text file, line after line
    10x !

    If you search in THIS forum with e.g. read lines from file, you will find answers like this one:
    Hi ! This is the answer for your query. This program prints as the output itself reading line by line.......
    import java.io.*;
    public class readfromfile
    public static void main(String a[])
    if you search in THIS forum, with e.g. read lines from text file
    try{
    BufferedReader br = new BufferedReader(new FileReader(new File("readfromfile.java")));
    while(br.readLine() != null)
    System.out.println(" line read :"+br.readLine());
    }catch(Exception e)
    e.printStackTrace();
    }

  • I want to read lines from file, count it and extract numbers from a first line.

    i must do un loop?

    HI,
    i try to explain how to use to LABVIEW TOOLS...
    1. USE a for next loop
    2. here you must open the file with the VI. read lines from file.
    you can choos how many lines you read at same time.
    3. the string you can convert into an number.
    4. in the loop is the literal counter... this is you line couter....
    iun schrieb:
    > i must do un loop?

Maybe you are looking for