Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 1st, 2006, 11:39 AM
Authorized User
 
Join Date: Sep 2006
Location: mumbai, maharashtra, India.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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\'


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Themes Information in SQL 2000 sudhakar_d191080 ASP.NET 2.0 Professional 0 June 8th, 2007 06:54 AM
Uploadng an image and saving path in sql 2000 !!! dagad ASP.NET 2.0 Basics 0 November 1st, 2006 11:38 AM
How to insert path of the image in sql server hoailing22 SQL Server 2000 0 February 28th, 2006 03:32 AM
Saving Image to sqlserver 2000 in binary format kvanchi General .NET 1 May 10th, 2005 07:24 AM
Saving image in SQL Server 2000 ashu_from_india ADO.NET 0 February 21st, 2005 01:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.