473,395 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

copy pdf file from local directory to sql database

Hi, i'm doing a project on generating a crystalreport and viewing it in a
pdf format. I'm using vb.net and sql server.

i managed to general the crystalreport, save it in local directory then view
it. but on the other hand i would also like to save the pdf file into my sql
database. this is the difficult part and also the part which i'm stuck now.
follows are all my code. hope there will be someone who can help me! thanks!

Dim myConnection As New SqlClient.SqlConnection()
myConnection.ConnectionString =
"server=(local);database=st;Trusted_Connection=yes ;timeout =45"
Dim MyCommand As New SqlClient.SqlCommand()
MyCommand.Connection = myConnection
Dim CommandStr As String

CommandStr = "execute usp_rpt_note @note_id= '" & Label_NoteID.Text & "'"
MyCommand.CommandText = CommandStr
MyCommand.CommandType = CommandType.Text
Dim MyDA As New SqlClient.SqlDataAdapter()
MyDA.SelectCommand = MyCommand
Dim myDS As New Note_DataSet()

MyDA.Fill(myDS, "usp_rpt_note")
Dim oRpt As New Note_CrystalReport1()
oRpt.SetDataSource(myDS)

oRpt.ResourceName = "Note_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_us er"))) &
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

filenamepdf = "D:\Inetpub\wwwroot\report\temp\" & filename & ".pdf"

DiskOpts.DiskFileName = filenamepdf

oRpt.ExportOptions.DestinationOptions = DiskOpts
oRpt.Export()

' Database operation variables
Dim connect As New SqlClient.SqlConnection("Initial Catalog=st;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 uploaded_file As String
Dim strFileUpload As String

'uploaded_file = Request.QueryString("strFileName")
strFileUpload = "d:\Inetpub\wwwroot\report\temp\" & filename & ".pdf"
filename = strFileUpload

'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
'Dim sContentType As String = imageStream.GetType.ToString
'File1.PostedFile.ContentType
Dim sContentType As String = "Application/pdf"
'Dim sContentType As System.IO.Stream = File1.PostedFile.InputStream
' Read the image data and close the stream
imageStream.Read(imageData, 0, imageStream.Length)
imageStream.Close()

' Save the image
cmd.CommandType = CommandType.StoredProcedure

p = New SqlClient.SqlParameter("@ImageData", SqlDbType.Image)
p.Value = imageData
cmd.Parameters.Add(p)

p = New SqlClient.SqlParameter("@ContentType", SqlDbType.NVarChar)
p.Value = sContentType
cmd.Parameters.Add(p)

connect.Open()

cmd.ExecuteNonQuery()
connect.Close()

cmd.Dispose()
connect.Dispose()

Dim strPDF As String
strPDF = "./temp/" & filename & ".pdf"
Response.Redirect(strPDF)

Somehow it didnt work! i'm calling the above codes as a function in my
pageload.

Hope help is given! thanks!!

--
argeam - forum member
http://www.visual-basic-data-mining.net/forum
Nov 21 '05 #1
0 1080

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Manny | last post by:
My website uses php/mysql/linux and is hosted by a local web-hosting company. I access the db via cpanel/phpmyadmin and currently perform all testing and changes on the live db and website ( not...
11
by: Mike | last post by:
I want to be able to copy a directory of files (all .HTM files) from a network drive to a local drive on the machine c:\HTMFiles , How can i do that? I tried File.Copy(source, dest) but i need...
0
by: argeam | last post by:
Hi, i'm doing a project on generating a crystalreport and viewing it in a pdf format. I'm using vb.net and sql server. i managed to general the crystalreport, save it in local directory then...
4
by: Jon Asher | last post by:
Hi, I'm trying to do a simple import of a comma delimited text file with COPY but it's returning an error. The file has been granted all permissions in Linux, so it's not clear to me what the...
12
by: alanchinese | last post by:
i am a db2 newbie. we have a server hosting a db2/6000 database that restricts the use of backup, generate ddl. i wonder if there is a simple way to transfer the database structure and data into my...
4
by: eholz1 | last post by:
Hello PHP group, I am trying to use the copy function to copy files from one directory to another. This does not seem to work for me. What am I missing? Below is the code I am using. ...
0
by: Paul Brady | last post by:
I volunteer at a youth ministry agency and help them with their student database. They have two computers, both running Windows XP. Both have Office 2002 installed without Access, except that...
1
by: Mrozik | last post by:
Hi! I have Web Application with forms authentication. Data and security model resides in Oracle database. I have 'login' page with MS 'Login' control. In my LoggingIn event for debug purposes I...
4
by: maheswaran | last post by:
Hi, I copy the file from local to server using "Copy" function. see Copy($localfile,"Document/01/$file) The number 01 is incresing dynamically according to number of files in a folder....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.