01.
02.
Dim
imbByte(fUpload.PostedFile.InputStream.Length)
As
Byte
03.
fUpload.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length)
04.
05.
06.
Dim
ExtType
As
String
= System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower()
07.
Dim
strMIME
As
String
=
Nothing
08.
Select
Case
ExtType
09.
Case
".gif"
10.
strMIME =
"image/gif"
11.
Case
".jpg"
,
".jpeg"
,
".jpe"
12.
strMIME =
"image/jpeg"
13.
Case
".png"
14.
strMIME =
"image/png"
15.
Case
Else
16.
Me
.lblStatus.Text =
"Invalid file type."
17.
Exit
Sub
18.
End
Select
19.
20.
21.
Dim
objConn
As
New
SqlConnection
22.
Dim
strConnString, strSQL
As
String
23.
24.
strConnString =
"Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
25.
26.
strSQL =
"INSERT INTO files (Name,FilesName,FilesType) "
& _
27.
" VALUES "
& _
28.
" (@sName,@sFilesName,@sFilesType)"
29.
objConn.ConnectionString = strConnString
30.
objConn.Open()
31.
32.
Dim
objCmd
As
New
SqlCommand(strSQL, objConn)
33.
objCmd.Parameters.AddWithValue(
"@sName"
,
Me
.txtName.Text)
34.
objCmd.Parameters.AddWithValue(
"@sFilesName"
, imbByte)
35.
objCmd.Parameters.AddWithValue(
"@sFilesType"
, strMIME)
36.
objCmd.ExecuteNonQuery()
37.
38.
objConn.Close()
39.
objConn =
Nothing