Reading File Documents

G

Guest

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?
 
G

Guest

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
 
G

Guest

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
 
J

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top