Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-09-10 : 08:35:46
|
Elaine writes "Hi I've just pass by your website and saw the thing i'm looking for. i'm using asp.net and sql server 2000. i need some help on uploading and retrieving of pdf file. what my program does is simply upon a click of a hyper link, the program generates a crystalreport in local directory, copy the file from the directory to the database. Now i'm stuck with retrieving it from the database then displaying back the pdf file without having to go to the directory to generate the report again. Below is my codes. Hope you can be able to help me! thanks!Sub BindReport() Dim myConnection As New SqlClient.SqlConnection() myConnection.ConnectionString = "server=(local);database=workflow_student;Trusted_Connection=yes;timeout =45" Dim MyCommand As New SqlClient.SqlCommand() MyCommand.Connection = myConnection Dim CommandStr As String CommandStr = "execute usp_rpt @NID= '" & Label_NID.Text & "'" MyCommand.CommandText = CommandStr MyCommand.CommandType = CommandType.Text Dim MyDA As New SqlClient.SqlDataAdapter() MyDA.SelectCommand = MyCommand Dim myDS As New N_DataSet() MyDA.Fill(myDS, "usp_rpt") Dim oRpt As New N_CrystalReport1() oRpt.SetDataSource(myDS) oRpt.ResourceName = "N_CrystalReport1.rpt" Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions() oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile oRpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat Dim filename, filenamepdf, filenamexls As String filename = UCase(Logon_Name(Request.ServerVariables("LOGON_user"))) & CStr(Year(Now())) & CStr(Month(Now())) & CStr(Day(Now())) & CStr(Hour(Now())) & CStr(Minute(Now())) & CStr(Second(Now())) & CStr(CInt(Int((100000 * Rnd(200)) + 1))) filename = filename ' Bala not need this filenamepdf = "c:\Inetpub\wwwroot\mpc\Report\temp\" & filename & ".pdf" ' Bala not need this filenamexls = "c:\Inetpub\wwwroot\mpc\Report\temp\" & filename & ".xls" filenamepdf = "D:\Inetpub\wwwroot\report\temp\" & filename & ".pdf" 'filenamexls = "D:\Inetpub\wwwroot\eMPC\Report\temp\" & filename & ".xls" HyperLink1.NavigateUrl = "./temp/" & filename & ".pdf" Dim strLink = "./temp/" & filename & ".pdf" 'HyperLink_xls.NavigateUrl = "./temp/" & filename & ".xls" DiskOpts.DiskFileName = filenamepdf oRpt.ExportOptions.DestinationOptions = DiskOpts oRpt.Export() ''/////////////Save the uploaded file from a local directory into the database/////////////// ' Database operation variables Dim connect As New SqlClient.SqlConnection("Initial Catalog=workflow_student;Data Source=localhost;Integrated Security=SSPI;Persist Security Info=True;") Dim cmd As New SqlClient.SqlCommand("usp_copy_frm_directory", connect) Dim p As SqlClient.SqlParameter 'Dim FileName As String Dim uploaded_file As String 'Dim strFileUpload As String 'strFileUpload = "d:\Inetpub\wwwroot\testelaine\uploaded\" + strFileName filenamepdf = "D:\Inetpub\wwwroot\report\temp\" & filename & ".pdf" filename = filenamepdf 'File/data variables Dim imageStream As New IO.FileStream(filename, IO.FileMode.Open) 'Dim imagestream As New IO.FileStream(Server.MapPath("ToBeUpload.doc"), IO.FileMode.Open) Dim imageData(imageStream.Length) As Byte Dim FileSize As Integer = CType(imageStream.Length, Integer) Dim UploadDate As DateTime = DateTime.Now |
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2004-09-10 : 09:13:19
|
Could you just create the pdf in memory and stream it to the browser? |
 |
|
|
|
|