By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,640 Members | 1,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,640 IT Pros & Developers. It's quick & easy.

Determing internal format of file

P: n/a
RD
We're picking up files on an FTP server using a vb.net program. We need to
know if the file we pick up is an ASCII comma separated file or if it is in
an Exel format without relying on the extension of the file name
exclusively. So we have to look in the file itself using Vb .Net program
code.

By looking at the contents of the file using a function or sub, how can we
determine reliably if it is an ASCII file or an Excel file?

Thanks for any help,

Bob
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
read 2 or 3 lines - count the commas in each line - if all 3 lines contain
the same number of commas,
i bet its a comma-delimited file - or you could check for chars unique to
excel files (you have to look to see)
"RD" <no****@nospam.net> wrote in message
news:uy**************@TK2MSFTNGP11.phx.gbl...
We're picking up files on an FTP server using a vb.net program. We need to
know if the file we pick up is an ASCII comma separated file or if it is in an Exel format without relying on the extension of the file name
exclusively. So we have to look in the file itself using Vb .Net program
code.

By looking at the contents of the file using a function or sub, how can we
determine reliably if it is an ASCII file or an Excel file?

Thanks for any help,

Bob

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 20 '05 #2

P: n/a
> By looking at the contents of the file using a function or sub, how
can we determine reliably if it is an ASCII file or an Excel file?


Prior to Excel 2003 (which changed the format of .xls files), Excel files
were binary files. If you open one in a binary editor (or a good text editor
such as Ultra Edit) you'll find that the first 100 or so bytes primarily
consist of either 0x00 of 0xff characters (there are others too but there
are lots of these). These characters will never appear in a .csv file unless
it has been corrupted. So you could just open it, scan the first 64 bytes or
so and see if any contain 0x00 or 0xff. If they do it's an Excel file. If
they don't, it's not (though that doesn't necessarily mean that is is a .csv
file, of course).

I've no idea about the format in which Excel 2003 files are stored, but
wouldn't be surprised if they're XML-based (in which case they would be
ASCII files, you'll need to find this out).

ASCII files should only ever contain characters in the range 32-127
(inclusive), as well as ascii 10 and 13 (line feed and carriage return).

Hope that's of some help,

--

(O)enone
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.