Click here to Skip to main content
11,923,958 members (64,011 online)
Rate this:
Please Sign up or sign in to vote.
See more: .NET3.5 C# ASP.NET .NET
Dear All,

I need some help in converting a byte array "Which Came From DataBase" to pdf. Could someone give me an example of how in C#? Here is what I have so far,

using System.IO;
string sFile = "c:\testpdf.pdf"; //Path
FileStream fs = File.Create(sFile);
BinaryWriter bw = new BinaryWriter(fs); 

And I have Used This To Convert The Pdf File Into Byte Array:

byte[] picArray= System.IO.File.ReadAllBytes(filePathName);

thanks in advance,
Posted 29-May-11 23:26pm
Edited 29-May-11 23:31pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You seem to be trying to write a byte arry from a database into a file: why is this giving you problems? If you have the bytes, just write them:
File.WriteAllBytes(@"C:\testpdf.pdf", myArrayOfBytes);
(You should be aware that this is likely to fail - permissions problems often prevent writes to the root directory of a HDD - try using a subdirectory instead)
moral_2011 30-May-11 5:33am
Thank You It Is working With Me now
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

MemoryStream ms = new MemoryStream(pdfBytearray); 
Response.ContentType = "application/pdf"; 
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf"); 
Response.Buffer = true; 
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If it is a byte array, you can write it to disk so it becomes saved as *pdf file.
either, you can write the bytes to the response output stream and user will be prompt to download and save the file.

Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline;filename=data.pdf");
Response.BufferOutput = true;
byte[] pdf;
Response.AddHeader("Content-Length", response.Length.ToString());

Can you please have a look at this code. I got it from the link given below.[^]

Hope this will help you.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151125.3 | Last Updated 30 May 2011
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