Click here to Skip to main content
15,886,963 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: "External table is not in the expected format." how to solve this error? Pin
J4amieC29-Jul-08 22:11
J4amieC29-Jul-08 22:11 
QuestionHow to resize the ContentPlaceHolder of a MasterPage in Child(.aspx) Page? Pin
mcmilan29-Jul-08 18:40
mcmilan29-Jul-08 18:40 
QuestionFile Upload error on live site. Pin
JimBob SquarePants29-Jul-08 18:33
JimBob SquarePants29-Jul-08 18:33 
AnswerRe: File Upload error on live site. Pin
Venkatesh Mookkan29-Jul-08 18:50
Venkatesh Mookkan29-Jul-08 18:50 
GeneralRe: File Upload error on live site. Pin
JimBob SquarePants29-Jul-08 19:03
JimBob SquarePants29-Jul-08 19:03 
AnswerRe: File Upload error on live site. Pin
Anand Desai29-Jul-08 19:14
Anand Desai29-Jul-08 19:14 
GeneralRe: File Upload error on live site. Pin
Venkatesh Mookkan29-Jul-08 19:16
Venkatesh Mookkan29-Jul-08 19:16 
GeneralRe: File Upload error on live site. Pin
JimBob SquarePants29-Jul-08 22:52
JimBob SquarePants29-Jul-08 22:52 
Ok Firstly I'll give you all a quick runthrough of what I'm doing.

Essentially I'm Identifing the file, loading and resizing it in memory and producing a System.Data.Linq.Binary object that is uploaded to my database.

All this works when I'm running the website on my local machine. The live version can't find the file.

Here Goes:

'----------------------------------------------------------------------------------
    ' Name              : btnAddPhoto_Click
    ' Purpose           : This event handles the Conversion of the uploaded image files to System Data Linq Binary.
    '----------------------------------------------------------------------------------

    Protected Sub btnAddPhoto_Click(ByVal sender As Object, ByVal e As System.EventArgs) 'Handles btnAddPhoto.Click

        Dim photoFileUpload As FileUpload = CType(dvCrops.FindControl("photoFileUpload"), FileUpload)


        If photoFileUpload.PostedFile Is Nothing Then

            lblMessage.Text = "No file specified."

            Exit Sub

        Else

            Dim FileName As String = photoFileUpload.PostedFile.FileName


            Dim ext As String = FileName.Substring(FileName.LastIndexOf("."))

            ext = ext.ToLower


            If ext = ".jpg" Then

            ElseIf ext = ".bmp" Then

            ElseIf ext = ".gif" Then

            ElseIf ext = "jpg" Then

            ElseIf ext = "bmp" Then

            ElseIf ext = "gif" Then

            Else

                lblMessage.Text = "Only gif, bmp, or jpg format files supported."

                Exit Sub

            End If

            ' convert the fileupload.postedfile to system.data.linq.binary
            Dim source As FileInfo = New FileInfo(FileName)
            Dim buffer() As Byte = New Byte(photoFileUpload.PostedFile.ContentLength - 1) {}
            source.OpenRead.Read(buffer, 0, photoFileUpload.PostedFile.ContentLength)


            buffer = ResizeImageFile(buffer, 200)
            crpImage1 = New System.Data.Linq.Binary(buffer)
            lblMessage.Text = "Image Successfully Uploaded."
        End If

    End Sub


ResizeImageFile refers to this:

Public Shared Function ResizeImageFile(ByVal imageFile() As Byte, ByVal targetSize As Integer) As Byte()
        Using oldImage As System.Drawing.Image = System.Drawing.Image.FromStream(New MemoryStream(imageFile))
            Dim newSize As Size = CalculateDimensions(oldImage.Size, targetSize)
            Using newImage As Bitmap = New Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb)
                Using canvas As Graphics = Graphics.FromImage(newImage)
                    canvas.SmoothingMode = SmoothingMode.AntiAlias
                    canvas.InterpolationMode = InterpolationMode.HighQualityBicubic
                    canvas.PixelOffsetMode = PixelOffsetMode.HighQuality
                    canvas.DrawImage(oldImage, New Rectangle(New Point(0, 0), newSize))
                    Dim m As New MemoryStream
                    newImage.Save(m, ImageFormat.Jpeg)
                    Return m.GetBuffer
                End Using
            End Using
        End Using
    End Function


Calculate Dimensions to this:

Public Shared Function CalculateDimensions(ByVal oldSize As Size, ByVal targetSize As Integer) As Size
        Dim newSize As Size
        If (oldSize.Height > oldSize.Width) Then
            newSize.Width = CType((oldSize.Width * CType((targetSize / CType(oldSize.Height, Single)), Single)), Integer)
            newSize.Height = targetSize
        Else
            newSize.Width = targetSize
            newSize.Height = CType((oldSize.Height * CType((targetSize / CType(oldSize.Width, Single)), Single)), Integer)
        End If
        Return newSize
    End Function


Hope this clears everything up.

Thanks in advance!

JimBob SquarePants
*******************************************************************
"He took everything personally, including our royalties!"
David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager
*******************************************************************

GeneralRe: File Upload error on live site. Pin
Venkatesh Mookkan30-Jul-08 0:17
Venkatesh Mookkan30-Jul-08 0:17 
GeneralRe: File Upload error on live site. Pin
JimBob SquarePants30-Jul-08 1:31
JimBob SquarePants30-Jul-08 1:31 
GeneralRe: File Upload error on live site. Pin
Venkatesh Mookkan30-Jul-08 2:12
Venkatesh Mookkan30-Jul-08 2:12 
GeneralRe: File Upload error on live site. Pin
JimBob SquarePants30-Jul-08 4:03
JimBob SquarePants30-Jul-08 4:03 
GeneralRe: File Upload error on live site. Pin
Venkatesh Mookkan30-Jul-08 17:50
Venkatesh Mookkan30-Jul-08 17:50 
GeneralRe: File Upload error on live site. Pin
JimBob SquarePants31-Jul-08 3:17
JimBob SquarePants31-Jul-08 3:17 
AnswerRe: File Upload error on live site. Pin
Imran Khan Pathan29-Jul-08 20:00
Imran Khan Pathan29-Jul-08 20:00 
AnswerRe: File Upload error on live site. Pin
Anand Desai29-Jul-08 20:13
Anand Desai29-Jul-08 20:13 
QuestionDetermine if transaction is successful [modified] Pin
ASPnoob29-Jul-08 15:52
ASPnoob29-Jul-08 15:52 
AnswerRe: Determine if transaction is successful Pin
Christian Graus29-Jul-08 17:49
protectorChristian Graus29-Jul-08 17:49 
GeneralRe: Determine if transaction is successful Pin
Mogaambo29-Jul-08 18:37
Mogaambo29-Jul-08 18:37 
GeneralRe: Determine if transaction is successful Pin
Christian Graus29-Jul-08 20:08
protectorChristian Graus29-Jul-08 20:08 
QuestionChameleon Experience Pin
Aslesh29-Jul-08 5:06
Aslesh29-Jul-08 5:06 
QuestionAn error has occurred while establishing a connection to the server Pin
attalurisubbu29-Jul-08 3:42
attalurisubbu29-Jul-08 3:42 
AnswerRe: An error has occurred while establishing a connection to the server Pin
eyeseetee29-Jul-08 4:19
eyeseetee29-Jul-08 4:19 
AnswerRe: An error has occurred while establishing a connection to the server Pin
Christian Graus29-Jul-08 12:40
protectorChristian Graus29-Jul-08 12:40 
Questionajax dual slider control asp.net c# 2.0 Pin
VijayVishwakarma29-Jul-08 2:33
VijayVishwakarma29-Jul-08 2:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.