473,467 Members | 1,291 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

varbinary(max) to pdf in vb.net

3 New Member
Hello,

I wanted code to convert the varbinry to pdf and save it on Clients machine.
Can anyone help me ??
Oct 7 '09 #1
4 20220
Plater
7,872 Recognized Expert Expert
Well varbinary should return a byte array. Assuming it was populated correctly, you can save the byte array as a file and give it a .pdf extension.
Oct 7 '09 #2
ssnaik84
149 New Member
check iTextSharp Library tutorial.
you just have to send binary data to PdfWriter object and set some properties.
Oct 8 '09 #3
ssnaik84
149 New Member
wait.. If you are developing web application, you dont need even that.
you just have to
Expand|Select|Wrap|Line Numbers
  1. Response.ContentType = "application/pdf"
Oct 8 '09 #4
salonisona
3 New Member
First of all Thanks both of you.
I got the solution.Actually my senario was ,I had stored the pdf in SQL SEVER 2005 as varbinary(max) type and I wanted to retriew the pdf back.
Solution for this is as below :
In web we can use Response Content type as said by ssnaik .I have found the following solution.

in vb6
----------
Private Sub ByteArrayToPDFConverter_Click()

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim mstream As ADODB.Stream

Set cn = New ADODB.Connection
cn.Open "Provider=SQLOLEDB;data Source=test;Initial Catalog=test;User Id=_test;Password=test"

Set rs = New ADODB.Recordset
rs.Open "Select document from tbltest where id = 13", cn, adOpenKeyset, adLockOptimistic
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs.Fields("document").Value
mstream.SaveToFile "c:\ByteTopdf.pdf", adSaveCreateOverWrite


rs.Close
cn.Close
--------------------------------------------------------------------------------
in c# for web application
--------
while (reader.Read())
{
bFileData = (byte[])reader["doc"];
Response.BufferOutput = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename=" + file.Name);
//Response.AddHeader("content-disposition", "attachment;filename=Test.pdf");
Response.BinaryWrite(bFileData);
Response.Flush();
Response.End();
}

and using Filestream
--------------------------------
bFileData = (byte[])reader["doc"];

using (FileStream stream = File.Open("C:\\file.pdf", FileMode.Create))
{
stream.Write(bFileData, 0, bFileData.Length);
}
-----------------
in vb.net
------------------
Private Sub SqlBlob2File(ByVal DocName As String)

Dim cn As New SqlConnection(My.Settings.DocStoreConnectionString .ToString())
Dim cmd As New SqlCommand("Select DocData From Documents WHERE DocName = @DocName", cn)

cmd.Parameters.AddWithValue("@DocName", DocName)

cn.Open()

Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read() Then
Dim fs As IO.FileStream = New IO.FileStream(IO.Path.Combine(Me.FolderBrowserDial og1.SelectedPath, DocName), IO.FileMode.Create)
Dim b() As Byte = dr.Item("DocData")
fs.Write(b, 0, b.Length)
fs.Close()
End If
End Using 'dr

cn.Close()

Best Regards
Sona
Oct 8 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bill Nguyen | last post by:
I need sample code to insert binary file (mappoint map file) into a varbinary column using VB.NET. Please help! Thanks Bill
5
by: =?Utf-8?B?ZHZhcm1h?= | last post by:
Hi I am executing a Sql Server SP from my C# app One of the parameters is of type varbinary. Since the content length of this parameter is variable I cannot set it to a pre-defined length. What...
1
by: Karch | last post by:
I am doing some experimenting with serialization (for use with Service Broker) and I am having a problem converting from a .NET DateTime (in the client application) to a SqlDbType.VarBinary (as...
7
by: gsauns | last post by:
Not sure if this is belongs here, or maybe in SQL... I have a SQL Server 2005 database where I store a varbinary(MAX) field. In my Web form, I allow the user to upload a photo to the database....
2
by: tindersticks | last post by:
Hi Can someone please post the simplest script that will allow an asp page read and write to/from m a MS SQL varbinary(max) field. ie image or doc/pdf etc is converted to relevant format and...
1
by: Gilad | last post by:
Hi I moved to SQL Server 2005 (from 2000) and noticed there is a better variable to deal with binary arrays. I hava a table that hold 9 columns of images (BLOB). each array has a different size...
4
by: Martin Horst | last post by:
Hi, I've got an application which is written in .Net 1.1. When I try to write a varbinary(max) field using the SqlCommand and SqlParameter classes I got an exception like this: "The...
1
by: quartrj | last post by:
For number of security reasons I can't use the Openrowset - Bulk option does any know of another way to load files into this data type.
1
by: quintonmartin | last post by:
Here's my problem. I have a client application that uses a web service for data access. I can read/update many records in many tables, however, I am not getting what I expect for a varbinary(max)...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.