|
|
 |
| ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

November 1st, 2006, 10:39 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Location: mumbai, maharashtra, India.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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\'
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |