Results 1 to 2 of 2

Thread: Binary Reader - Read a file

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    5

    Binary Reader - Read a file

    I am trying to read a file to a string..
    But only reads the first characters and it stops

    Code:
    public class ItemReader
        {
            public string ReadWDF(string Location)
            {
                string ret = "";
    
                StreamReader _Reader = new StreamReader(Location);
    
                string _Contents = _Reader.ReadToEnd();
    
                if (_Contents != "")
                {
                    ret = _Contents;
                    return ret;
                }
                else
                {
                    return ret;
                }
            }
        }
    I am trying to read a world of warcaft cache file to make a database.

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

    Re: Binary Reader - Read a file

    Your thread title says "Binary Reader" yet your code uses a StreamReader. They are two different things for two different purposes. A StreamReader is for reading text files. Is the file you're reading a text file or a binary file?

    Also, your entire method could be reduced to a single line:
    csharp Code:
    1. return System.IO.File.ReadAllTtext(location);
    That will produce exactly the same behaviour, except that it will actually close the file too.

    I also suggest that you strive for some consistency in your nomenclature. You're using three different conventions for variables. Pick one and stick with it. Unless you have some reason to do otherwise, all your method parameters and local variables should start with a lower-case letter; no upper-case letter and no underscore.
    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

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