Solved

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

Posted on 2016-11-18
4
32 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now