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