Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I surfed google very much for days to get an answer for a below query. I would highly appreciate if any can help me to come out of this problem.
 
We have Different types of files stored in an Image Datatype column in sql server as a byte array but we dnt have an extension of that file. I have to print all records files which are saved as a byte array in an image data type if they satisfied a condition. My problem is to achieve this functionality and for that I am looking for a solution like if there is any way by which can do following stuff.
 
1) If I can directly send bytes array to a printer.
2) If I can convert bytes array of all records to a pdf file and than send this generated pdf to a printer.
3) The solutions I found on google works only if I know file type of that bytes but there is no way to get a file type of those bytes.
4) I passed through lot of forums and examples but none of them are working.
 
I am very much thankful to you for reading out.
 
Thanks and Regards,
Chintan Desai
Posted 26-Jul-12 1:46am
Edited 26-Jul-12 1:48am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can't.
 
There is no guaranteed way to identify a file type from it's content. It may be possible for some files - "nice" data formats generally include a header which describes the content or app which created it - but there are a lot more "nasty" formats out there.
 
Even if you can identify the content, there is no way to just convert it to a PDF, unless you have either a direct converter for that specific file format, or a convert from the specific format to a generic format you can then convert to PDF.
 
Sending bytes directly to a printer will probably generate a load of printed pages covered with total rubbish!
  Permalink  
Comments
chintan.desai10 at 26-Jul-12 7:38am
   
Thanks for your comments but i got stuck with it and i have to do it any how.
so do you have any other alternatives except above ?
OriginalGriff at 26-Jul-12 8:04am
   
If you have a restricted number of file formats that the data could be, you can look at the format definition (the major formats are published) and inspect the data to try and match it. Otherwise, I'm sorry, but someone has made a huge mistake in not storing essentail data, and you may not be able to work round it - at least without a lot of work!
chintan.desai10 at 28-Jul-12 4:56am
   
yes i agree with you.I also tried with sending bytes to printer,.prn file from cpmmand prompt , diff 3rd party dll's but seems like no way.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
chintan.desai10 at 26-Jul-12 7:39am
   
Hi I dnt know file extension type so above link is not helpful.
Santhosh Kumar J at 26-Jul-12 7:41am
   
In the above link also file extensions are unknown at run time, i am getting file extension by separating the filename with '.' character
chintan.desai10 at 26-Jul-12 7:47am
   
i dn't have a file and only have byte array which i retrived from db.
Santhosh Kumar J at 26-Jul-12 7:53am
   
please check the solution in the below link
http://www.c-sharpcorner.com/Forums/Thread/179342/how-to-upload-and-retrieve-files-from-database.aspx
chintan.desai10 at 28-Jul-12 4:52am
   
Hi Santosh, thanks for a try but i dn't have a file name or its extension as i said previously.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,535
1 OriginalGriff 8,295
2 Peter Leow 4,839
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,301


Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 26 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100