473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Reading File Documents

I am reaing files of different format (PDF, XLS, CVS, XML, HTML). I will take
the output and store in in an image field in a database table. The following
is the code I am using to read the files.

public byte[] getBinaryFile(string pOutputPath)
{
FileInfo fi = new FileInfo(pOutputPath);
byte[] fileData = new byte[fi.Length];
FileStream fs = new FileStream(pOutputPath, FileMode.Open, FileAccess.Read);
BinaryReader bfs = new BinaryReader(fs);
bfs.Read(fileData, 0, (int)(fi.Length));
bfs.Close();
fs.Close();
return fileData;
}

This code seems to work for all file formats except PDF. It seems to corrupt
the PDF files. What should I be doing to handle PDF files?
Nov 16 '05 #1
1 1441

The function is called getBinaryFile, but then you pass back an array of
bytes?
I'm not sure that PDF's are stored in blocks of 8-bit characters. If they're
not, then this would definately not work.

CVS, XML and HTML files are all just text files, even though these can still
be in a unicode format which means that every other byte in the array you
pass back would be null. I'm not sure how this would affect the files if you
were to write them back out as ASCII files again.

Normally in this sort of scenario, the files are stored to disk as they are,
and then linked from the database. This also saves a tremendous about of
space in the database.

Hope that helps.

Daniel.

"AlanS" <Al***@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
I am reaing files of different format (PDF, XLS, CVS, XML, HTML). I will
take
the output and store in in an image field in a database table. The
following
is the code I am using to read the files.

public byte[] getBinaryFile(string pOutputPath)
{
FileInfo fi = new FileInfo(pOutputPath);
byte[] fileData = new byte[fi.Length];
FileStream fs = new FileStream(pOutputPath, FileMode.Open,
FileAccess.Read);
BinaryReader bfs = new BinaryReader(fs);
bfs.Read(fileData, 0, (int)(fi.Length));
bfs.Close();
fs.Close();
return fileData;
}

This code seems to work for all file formats except PDF. It seems to
corrupt
the PDF files. What should I be doing to handle PDF files?

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: hokiegal99 | last post by:
This is not really a Python-centric question, however, I am using Python to solve this problem (as of now) so I thought it appropiate to pose the question here. I have some functions that search...
7
by: BlueOysterCult | last post by:
Hello all I have a project that I have to read the file - which I have done I can see the file output. I then need to read the line - parse the line into three separate values (there are 3 = name...
3
by: tigrrgrr42 | last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am currently bringing them from a byte array into a temp file to pop into word and make word do its thing as a com object. ...
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
5
by: Anja | last post by:
Hi everyone, I have a question about text file reading with VBA. I want to read he whole contents of the file in one string variable. I have been able to successfully read lines using: Line...
1
by: perryd | last post by:
I'm tring to read a file using Textpad in c langugage. When I go to run and put in cmd I get C:\Documents and Settings\Owner> then when I put in cd my documents i get C:\Documents and...
5
by: jeff | last post by:
i stated using a python module called id3reader (http://www.nedbatchelder.com/code/modules/id3reader.html) and i tried to use it to organize all my music files (right now they are all in one...
7
madhoriya22
by: madhoriya22 | last post by:
Hi, I am trying to read a file sent from client to server. Here is how I am trying it .... String filePath = request.getParameter("SelectCSVFile"); System.out.println("path:::---> "+filePath);...
4
by: amphibian1 | last post by:
I'm trying to write a C# application that iterates through a collection of Microsoft Office documents and standardizes the meta data of those documents (e.g. the author and company name). ...
16
by: billsahiker | last post by:
I am researching for an upcoming c# .net 2.0 project that may require reading and writing xml files. I don't want to use xmltextreader/ xmltextwriter as I prefer to have lower level file access...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.