Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.5 C# ASP.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:
 
FileUpload1.SaveAs(filePathName);
byte[] picArray= System.IO.File.ReadAllBytes(filePathName);
 
thanks in advance,
Posted 29-May-11 23:26pm
Edited 29-May-11 23:31pm
v3
Rate this: bad
good
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)
  Permalink  
Comments
moral_2011 at 30-May-11 5:33am
   
Thank You It Is working With Me now
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Response.Clear(); 
MemoryStream ms = new MemoryStream(pdfBytearray); 
Response.ContentType = "application/pdf"; 
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf"); 
Response.Buffer = true; 
ms.WriteTo(Response.OutputStream); 
Response.End(); 
  Permalink  
Rate this: bad
good
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.
or
either, you can write the bytes to the response output stream and user will be prompt to download and save the file.
 
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline;filename=data.pdf");
Response.BufferOutput = true;
byte[] pdf;
Response.AddHeader("Content-Length", response.Length.ToString());
Response.BinaryWrite(pdf);
Response.End();
 
Can you please have a look at this code. I got it from the link given below.
 
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/6810a67f-66d9-4ce4-87e5-06dbbb754730/[^]
 
Hope this will help you.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 562
1 Sergey Alexandrovich Kryukov 484
2 Maciej Los 325
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 30 May 2011
Copyright © CodeProject, 1999-2014
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