Uploadng an image and saving path in sql 2000 !!!
well, i'm using vs2005 and sql server 2000.
i've got this snippet for uploading an image and creating itz thumbnail and also saving the thumbnail and the original image in a folder.
but i also want the path of the image and the thumbnail to be stored in sql 2000 database, instead of saving the images in sql.
can some one plz provide me the way.
thanx in advance.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
' Initialize variables
Dim sSavePath As String
Dim sThumbExtension As String
Dim intThumbWidth As Integer
Dim intThumbHeight As Integer
' Set constant values
sSavePath = ".\Image\"
sThumbExtension = "_thumb"
intThumbWidth = 160
intThumbHeight = 120
' If file field isnât empty
If Not fileUpEx.PostedFile Is Nothing Then
' Check file size (mustnât be 0)
Dim myFile As HttpPostedFile = fileUpEx.PostedFile
Dim nFileLen As Integer = myFile.ContentLength
If nFileLen = 0 Then
lblStatus.Text = "No file was uploaded."
Return
End If
' Check file extension (It must be .JPG)
If System.IO.Path.GetExtension(myFile.FileName).ToLow er() = ".jpg" Then
' Read file into a data stream
Dim myData() As Byte = New Byte(nFileLen) {}
myFile.InputStream.Read(myData, 0, nFileLen)
' Make sure a duplicate file doesnât exist. If it does, keep on appending an
' incremental numeric until it is unique
Dim sFilename As String = System.IO.Path.GetFileName(myFile.FileName)
Dim file_append As Integer = 0
While System.IO.File.Exists(Server.MapPath(sSavePath + sFilename))
file_append = file_append + 1
sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile. FileName) + file_append.ToString() + ".jpg"
End While
' Save the stream to disk
Dim NewFile As System.IO.FileStream = New System.IO.FileStream(Server.MapPath(sSavePath + sFilename), System.IO.FileMode.Create)
NewFile.Write(myData, 0, myData.Length)
NewFile.Close()
' Check whether the file is really a JPEG by opening it
Dim myCallBack As System.Drawing.Image.GetThumbnailImageAbort = New System.Drawing.Image.GetThumbnailImageAbort(Addres sOf ThumbnailCallback)
Dim myBitmap As Drawing.Bitmap
Try
myBitmap = New Drawing.Bitmap(Server.MapPath(sSavePath + sFilename))
' If jpg file is a jpeg, create a thumbnail filename that is unique.
file_append = 0
Dim sThumbFile As String = System.IO.Path.GetFileNameWithoutExtension(myFile. FileName) + sThumbExtension + ".jpg"
While System.IO.File.Exists(Server.MapPath(sSavePath + sThumbFile))
file_append = file_append + 1
sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile. FileName) + file_append.ToString + sThumbExtension + ".jpg"
End While
' Save thumbnail and output it onto the webpage
Dim myThumbnail As System.Drawing.Image = myBitmap.GetThumbnailImage(intThumbWidth, intThumbHeight, myCallBack, IntPtr.Zero)
myThumbnail.Save(Server.MapPath(sSavePath + sThumbFile))
imgPicture.ImageUrl = sSavePath + sThumbFile
' Displaying success information
lblStatus.Text = "Image uploaded successfully!"
' Destroy objects
myThumbnail.Dispose()
myBitmap.Dispose()
Catch errArgument As ArgumentException
System.IO.File.Delete(Server.MapPath(sSavePath + sFilename))
End Try
Else
lblStatus.Text = "The file must have an extension of JPG or GIF"
Return
End If
End Sub
Public Function ThumbnailCallback() As Boolean
Return False
End Function
--------------------------------------------------
therez nothin' as impossible, bcaz the word itself says : 'i'-'m'-'possible'
__________________
--------------------------------------------------
therez nothin\' as impossible, bcaz the word itself says : \'i\'-\'m\'-\'possible\'
|