-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Bharat
Message 2 in Discussion
Hi,
You can use Image filed of SQL Server to store Word Document or anyother file.
You also need to use input type="File" to select a file for upload like this : <INPUT
type="file" ID="MyFile" />
Here is the code to upload
Dim oStream As Stream
Dim inNoRows As Int32
Dim oParm As SqlParameter
'Create Byte array
'MyFile is the ID of input type="file" control which should be marked to run at server
Dim btArray(MyFile.PostedFile.ContentLength - 1) As Byte
oStream = MyFile.PostedFile.InputStream
'From Stream to byte Array
inNoRows = oStream.Read(btArray, 0, btArray.Length)
oStream.Close()
Dim cn As SqlConnection = New SqlConnection(<ConnectionString>)
cn.Open()
'You can also use stored procedure here, for better performance
cmd.CommandText = "Update upload Set [EMAIL PROTECTED] Where uploadID=1"
cmd.CommandType = CommandType.Text
oParm = New SqlParameter("@Data", SqlDbType.Image, btArray.Length)
oParm.Direction = ParameterDirection.Input
oParm.Value = btArray
cmd.Parameters.Add(oParm)
inNoRows = cmd.ExecuteNonQuery()
cn.Close()
and code to download
Dim intImageColumn As Int32 = 0
Dim cn As SqlConnection = New SqlConnection(<Conection String>)
Dim cmd As SqlCommand = New SqlCommand("Select top 1 Data from upload", cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim bt(dr.GetBytes(intImageColumn, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(intImageColumn, 0, bt, 0, bt.Length)
dr.Close()
cn.Close()
Response.AppendHeader("content-disposition", "attachment; filename=" &
<NameOfTheFile>)
Response.ContentType = "application/x-octet-stream"
Response.BinaryWrite(bt)
Hope this will help you...
Thanks,
Bharat
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]