Monday, December 14, 2015

How to search delimnted text files with asp.net

Well, I had to look for a way to read in a delimented text file and separate the parts so I could work with the different data elements... here's what i got.


 private void codesearch()
        {
            string fileName = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath) + @"\rawdata2.txt";

            if (!string.IsNullOrEmpty(fileName))
            {
                string lineOfText = "";
                var filestream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                var file = new System.IO.StreamReader(filestream, System.Text.Encoding.UTF8, true, 128);
                                         
                int i = 0;

                while ((lineOfText = file.ReadLine()) != null)
                {
                    string[] datacolumn = lineOfText.Split('|');

                    foreach (string data in datacolumn)
                    {
                       

                        i++;
                    }
              
                }

                file.Close();
            }

No comments:

Post a Comment