p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
I forgot my password Register Now
Register | FAQ | Members List | Calendar | 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 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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 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
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\'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 10:38 AM
How to insert path of the image in sql server hoailing22 SQL Server 2000 0 February 28th, 2006 02: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 12:10 PM



All times are GMT -4. The time now is 07:24 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc