473,403 Members | 2,071 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,403 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?

Jul 21 '05 #1
3 1205
how were you able to say PDF files are being corrupted? i have the same
problem before and i thought just that.. it is being corrupted. my task was
to allow uploads on a site, store it on a SQL DB and stream them back in a
web page. I thought PDF files were being corrupted. But the actual scenario
is PDF reader can not synchronize with the stream. so it is better to write
the file somewhere and just open it after a copy of the image has been
successfully written. In my case, i wrote the image file in a web accessible
folder and redirect the page to that file.

HTH

"AlanS" wrote:
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?

Jul 21 '05 #2
You know what. You are right. I wrote the file to a temp directory from SQL
and it was fione. But when attempting to access through a page .... the
corrupt message appeared. So now I copy to local storage on demand and then
open it. Works like a champ.

Thanks
Jul 21 '05 #3
J L
Not sure this is on topic, but your process is very interesting to me
and I would like to learn more...are you creating a byte image of the
document in the database table and then latter writing this image back
out to a file with the same extension as the original so it can be
opened with the original app (Excel, PDF etc)? If so, can you share
the code to write the stored file back out?

TIA,
John

On Wed, 2 Feb 2005 13:19:05 -0800, "AlanS"
<Al***@discussions.microsoft.com> wrote:
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?


Jul 21 '05 #4

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.