Results 1 to 10 of 10

Thread: Pull data from Txt file?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Pull data from Txt file?

    I have a file that gets copied every second over network to update a txt file located at c:\folder\data.txt.

    The txt file contains data like:

    Code:
    name
    serial
    in
    out
    test
    All in a row. Currently I am using VB code to pull from this file into excel. I would like to pull this into C#. What is the best way to approach this? I have to use the offset command in VB to get the data set in the proper cells.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Pull data from Txt file?

    Please provide the actual format of the file, otherwisd we're just guessing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: Pull data from Txt file?

    Here is an example of the txt. I want to lay this out as if it where in excel so I can do conditional formatting, etc.
    Attached Files Attached Files

  4. #4
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Pull data from Txt file?

    First create object where you'll store data from the file.
    Next read each line(with TextReader) and add in appropriate property in object.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: Pull data from Txt file?

    I honestly have no clue how tO do that. Any chance you can provide code?

  6. #6
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: Pull data from Txt file?

    Quote Originally Posted by sentinelace View Post
    I honestly have no clue how tO do that. Any chance you can provide code?
    Here buddy: http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: Pull data from Txt file?

    I see two boxes of code. None that specify where the txt file actually resides. Also I need this in form view or any clean view to display on a monitor. A console window will not work.

  8. #8
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Pull data from Txt file?

    StreamReader("TestFile.txt") - This means the file is in the same directory with application.
    In Windows Forms you can select file with OpenFileDialog.
    In the example with open file dialog you have how to read content from file and put in stream. At the bottom you have and RichTextBox for displaying results.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Posts
    87

    Re: Pull data from Txt file?

    is form view the best option I want to make it look similar to an excel sheet?

  10. #10
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Pull data from Txt file?

    You can use datagridview in form to display the results.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width