Solved

reading a text file which contains double Quotes is truncading the record

Posted on 2016-11-18
4
50 Views
Last Modified: 2016-11-22
In my c# application I have a common file read process which read data from database tables, Excel & text files into a dataset called ds. However the text file I am currently trying to read has imbedded quotations and commas,

Segment from text file in question

!! Name:        FG Cover Sheet Printer Channel
!! Date:        June 21, 2003
!! Version:     1.0
CHANNEL "default"
       LIKE "stdout"  

I need to read each record as a single piece of text but when for example it encounters CHANNEL "default" only CHANNEL is read into the dataset and everything after that is truncated. How can I read the text as it is displayed above line by line into a dataset ?

Connection string being used

 
connString=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\TiosFolder\TiosDownloadFiles;  Extended Properties='text;HDR=Yes;FMT=Delimited;ReadOnly=False';


reading record
conn = genRead.GetConnection("ole", connString);
Adapter = genRead.GetDataAdapter("ole", connString, sqlStmt);

OleDbConnection conn = new OleDbConnection(connString);
conn.Close();
OleDbCommand cmd = new OleDbCommand(sqlStmt, conn);
conn.Open();

Adapter.Fill(ds);
0
Comment
Question by:pclarke7
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 41893680
If the double quote is not needed (meaning the field is always one word) then you can create a temporary file  in the same folder location with the quotes removed and read the new file instead.
0
 

Author Comment

by:pclarke7
ID: 41894416
Hi Miguel,
These are 3rd party files that I am processing and therefore I have no input into how they are formatted. There are double quotes embedded everywhere. I was hoping that there would be something that I could add to the connection string that would allow me to read the full record, regardless of whether it contains quotes or not.

regards
Pat
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 41894625
Even if there are 3rd party files, they must comply with a format,  (else you will no be able to use or read any useful info from them)
First of all, please determine whether that is the case, because from the question description and your previous comment, it seems that the delimiters are different in the following lines:
CHANNEL "default"
       LIKE "stdout"  

Open in new window

One possible solution that I use in the past is to use the TextFieldParser class and load the dataset manually. I know more it is more work but sometimes it is not possible to use OLE classes because the file format is not compliant.
0
 

Author Closing Comment

by:pclarke7
ID: 41898008
Thanks Miguel,
took your advise and looked for another method of reading the file. Ended up using System.IO.Streamreader to read the textfile which worked well and read each line as a single record.

regards
Pat
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question