Solved

Strange Error

Posted on 2011-02-18
4
266 Views
Last Modified: 2012-05-11
I'm getting this error on one of my pages. I have similar code on the whole site and it all works fine.
but on 2 different pages, it's acting strange and inconsistant.

this is the error I am getting


Compiler Error Message: BC30311: Value of type 'System.Web.UI.Control' cannot be converted to 'System.Drawing.Image'.


and this is where it's erroring
CType(cell.FindControl("ImageZoomPort"), Image).ImageUrl = "/" + Application("SysUserDir") + PictureThumb
            CType(cell.FindControl("ImageZoomPort"), Image).Attributes.Item("longdesc") = "/" + Application("SysUserDir") + Picture
            CType(cell.FindControl("ImageZoomPort"), Image).Width = ImageScale.ScaledImageWidth
            CType(cell.FindControl("ImageZoomPort"), Image).Height = ImageScale.ScaledImageHeight



works everywhere else but this page. I can't seem to figure out what's freaking the page or. err, or the conflict.

Any help would be greatly appreciated

 
Imports OboutInc.ImageZoom
Imports Obout.Grid
Imports System.IO
Imports Obout.Interface
Imports System.Drawing
Imports System.Drawing.Image

Partial Class AccountSettings_AddEditPictures
    Inherits System.Web.UI.Page

    Dim Dal As New DAL
    Dim FileUnlock As New FileUnlock

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim Script As String = "function ClientDelete_Deleting(sender) {" & _
" return confirm('Are you sure you want to delete this Picture?');" & _
" } "

        Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "Script", Script, True)


        'Dim CheckAquariumExists = Dal.CheckAquariumExists(Dal.GetUserID)
        'If CheckAquariumExists = True Then




        Dim Func = Request.QueryString("Func")

        If Func = Nothing Then

            MultiViewAddEditPictures.SetActiveView(ViewShowPictures)

        ElseIf Func = "Edit" Then
            MultiViewAddEditPictures.SetActiveView(ViewAddEditPictures)
            SuperFormAddEditPictures.DefaultMode = DetailsViewMode.Edit

        ElseIf Func = "View" Then
            MultiViewAddEditPictures.SetActiveView(ViewAddEditPictures)
            SuperFormAddEditPictures.DefaultMode = DetailsViewMode.ReadOnly

        ElseIf Func = "Add" Then
            MultiViewAddEditPictures.SetActiveView(ViewAddEditPictures)
            SuperFormAddEditPictures.DefaultMode = DetailsViewMode.Insert

        End If



        'ElseIf CheckAquariumExists = False Then
        'MultiViewAddEditPictures.SetActiveView(ViewNoAquarium)
        'End If
        'DropDownListAquariumsInsert.Items.Insert(0, New ListItem("Choose Aquarium", "Choose Aquarium"))
        'DropDownListAquariumsInsert.SelectedIndex = DropDownListAquariumsInsert.Items.IndexOf(DropDownListAquariumsInsert.Items.FindByText("Choose Aquarium"))

    End Sub

    'Delete Picturethumb in Page Unload
    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload

        If Session("Picture") IsNot Nothing Then
            If (File.Exists(Session("Picture").ToString())) Then
                File.Delete(Session("Picture").ToString())
                Session("Picture") = Nothing
            End If
        End If

        If Session("PictureThumb") IsNot Nothing Then
            If (File.Exists(Session("PictureThumb").ToString())) Then
                File.Delete(Session("PictureThumb").ToString())
                Session("PictureThumb") = Nothing
            End If
        End If

    End Sub

    Protected Sub GridAquariumsGalleryPictures_DeleteCommand(ByVal sender As Object, ByVal e As Obout.Grid.GridRecordEventArgs) Handles GridAquariumsGalleryPictures.DeleteCommand



        Dim PictureThumb = Server.MapPath("/" & Application("SysUserDir") & "/" & e.Record("PictureThumb"))
        Dim Picture = Server.MapPath("/" & Application("SysUserDir") & "/" & e.Record("Picture"))

        If File.Exists(Picture) Then
            FileUnlock.DeleteFileSafely(Picture)
            System.GC.Collect()
            File.Delete(Picture)
            Session("PictureThumb") = Picture
        End If

        If File.Exists(PictureThumb) Then
            FileUnlock.DeleteFileSafely(PictureThumb)
            System.GC.Collect()
            File.Delete(PictureThumb)
            Session("PictureThumb") = PictureThumb
        End If
        Dim AquariumPortfolioID = e.Record("AquariumPortfolioID")
        Dal.DeleteAquariumPortfolio(AquariumPortfolioID)



    End Sub

   

    Protected Sub GridAquariumsGalleryPictures_RowDataBound(ByVal sender As Object, ByVal e As Obout.Grid.GridRowEventArgs) Handles GridAquariumsGalleryPictures.RowDataBound




        If e.Row.RowType = GridRowType.DataRow Then

            Dim cell As GridDataControlFieldCell = CType(e.Row.Cells(1), GridDataControlFieldCell)
            Dim AquariumsID = CType(cell.FindControl("HiddenFieldAquariumsID"), HiddenField).Value
            'Dim AquariumsID As Integer = GridAquariums.Columns(0).DataField("AquariumsID").ToString
            Dim PictureThumb = CType(cell.FindControl("HiddenPictureThumb"), HiddenField).Value

            Dim Picture = CType(cell.FindControl("HiddenPicture"), HiddenField).Value

            'scale Picture-----------------------------------------------------

            Dim ImageScale As New ImageScale

            ImageScale.MaxWidth = 125
            ImageScale.MaxHeight = 125

            ImageScale.PictureThumbLocation = "/" + Application("SysUserDir") + Picture

            ImageScale.ImageScaler()

            'End Scale-------------------------------------------------------

            CType(cell.FindControl("ImageZoomPort"), Image).ImageUrl = "/" + Application("SysUserDir") + PictureThumb
            CType(cell.FindControl("ImageZoomPort"), Image).Attributes.Item("longdesc") = "/" + Application("SysUserDir") + Picture
            CType(cell.FindControl("ImageZoomPort"), Image).Width = ImageScale.ScaledImageWidth
            CType(cell.FindControl("ImageZoomPort"), Image).Height = ImageScale.ScaledImageHeight


            'get fileinfo
            Dim File As New FileInfo(Server.MapPath("/" & Application("SysUserDir") & "/" & Picture))
            If File.Exists = True Then

                CType(cell.FindControl("labelfilename"), Label).Text = File.Name

                'If Not CType(cell.FindControl("labelfilesize"), Label).Text = Nothing Then
                CType(cell.FindControl("labelfilesize"), Label).Text = File.Length.ToString("#,##0") & " KB"
                'End If
            End If
        End If




    End Sub

    Function GetPictureFormat(ByVal PictureThumbFormat As Object) As String

        If IsNothing(PictureThumbFormat) Or IsDBNull(PictureThumbFormat) Then
            Return "/Images/NoPhoto.jpg"
        Else
            Return "/" & Context.Application("SysUserDir") & PictureThumbFormat
        End If

    End Function

    Protected Sub SuperFormAddEditPictures_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles SuperFormAddEditPictures.DataBound

        If SuperFormAddEditPictures.CurrentMode = FormViewMode.Insert Or SuperFormAddEditPictures.CurrentMode = FormViewMode.Edit Or SuperFormAddEditPictures.CurrentMode = FormViewMode.ReadOnly Then

            SuperFormAddEditPictures.Rows(1).CssClass = "HideControl"
            SuperFormAddEditPictures.Rows(2).CssClass = "HideControl"

        End If

    End Sub

    Protected Sub SuperFormAddEditPictures_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewDeletedEventArgs) Handles SuperFormAddEditPictures.ItemDeleted

        Response.Redirect("/AccountSettings/AddEditPictures.aspx")

    End Sub

    Protected Sub SuperFormAddEditPictures_ItemDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewDeleteEventArgs) Handles SuperFormAddEditPictures.ItemDeleting

      

        Dim Picture = Server.MapPath("/" & Application("SysUserDir") & "/" & e.Values("Picture"))
        Dim PictureThumb = Server.MapPath("/" & Application("SysUserDir") & "/" & e.Values("PictureThumb"))

        If File.Exists(Picture) Then
            Session("PictureThumb") = Picture
            'FileUnlock.DeleteFileSafely(Picture)
            'System.GC.Collect()
            'File.Delete(Picture)
        End If

        If File.Exists(PictureThumb) Then
            Session("PictureThumb") = PictureThumb
            'FileUnlock.DeleteFileSafely(PictureThumb)
            'System.GC.Collect()
            'File.Delete(PictureThumb)
        End If

        'Response.Redirect("/AccountSettings/AddEditPictures.aspx")

    End Sub

    Protected Sub LinkButtonAddGalleryPicture_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonAddGalleryPicture.Click

     
        Response.Redirect("/AccountSettings/AddEditPictures.aspx?&Func=Add")


    End Sub

    Protected Sub SuperFormAddEditPictures_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles SuperFormAddEditPictures.ItemInserted

        Response.Redirect("/AccountSettings/AddEditPictures.aspx")

    End Sub

    Protected Sub SuperFormAddEditPictures_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles SuperFormAddEditPictures.ItemInserting

        Dim PicturePass
        Dim PictureThumbPass


        Dim fileLen As Integer
        Dim myStream As System.IO.Stream
        Dim ImgContentType As String
        Dim UserName = Dal.GetUserName(Dal.GetUserID)

        Dim FileUploadPicture As FileUpload = SuperFormAddEditPictures.FindControl("FileUploadInsertPicture")

        

        If FileUploadPicture.HasFile Then

            'Create Dir
            If Not Directory.Exists(Server.MapPath("\" + Application("SysUserDir") & "\" & UserName & "\AquariumPictureGallery\Picture\")) Then
                Directory.CreateDirectory(Server.MapPath("\" + Application("SysUserDir") & "\" & UserName & "\AquariumPictureGallery\Picture\"))
            End If
            'Create Dir
            If Not Directory.Exists(Server.MapPath("\" + Application("SysUserDir") & "\" & UserName & "\AquariumPictureGallery\PictureThumb\")) Then
                Directory.CreateDirectory(Server.MapPath("\" + Application("SysUserDir") & "\" & UserName & "\AquariumPictureGallery\PictureThumb\"))
            End If


            fileLen = FileUploadPicture.PostedFile.ContentLength
            ImgContentType = FileUploadPicture.PostedFile.ContentType

            Dim Input(fileLen) As Byte
            myStream = FileUploadPicture.PostedFile.InputStream
            myStream.Read(Input, 0, fileLen)

            'Response.Write(fileLen)
            'Response.End()

            Dim Filename = FileUploadPicture.PostedFile.FileName

            Dim Path1 = Server.MapPath("\" + Application("SysUserDir") & "\" & UserName & "\AquariumPictureGallery\Picture\" & Filename)
            Dim DataPath1 = "/" & UserName & "/AquariumPictureGallery/Picture/" & Filename

            Dim Path2 = Server.MapPath("\" + Application("SysUserDir") & "\" & UserName & "\AquariumPictureGallery\PictureThumb\" & Filename)
            Dim DataPath2 = "/" & UserName & "/AquariumPictureGallery/PictureThumb/" & Filename


            If File.Exists(Path1) Or File.Exists(Path2) Then

                'LabelPhotos.Text = "Photo has not been added to the system"
                LabelConfirm.Text = "This photo image already exists in the system"
                e.Cancel = True

            Else



                LabelConfirm.Text = ""
                Dim PictureInfoLarge = System.Drawing.Image.FromStream(myStream)




                'Get Picture To be Resized large
                Dim maxWidth1 As Integer = 800
                Dim maxHeight1 As Integer = 800
                Dim imgHeight1, imgWidth1 As Integer
                'Dim PictureInfo



                imgHeight1 = PictureInfoLarge.Height
                imgWidth1 = PictureInfoLarge.Width


                ' Determine Scaling
                If imgWidth1 >= maxWidth1 Or imgHeight1 >= maxHeight1 Then
                    'Determine what dimension is off by more
                    Dim deltaWidth1 As Integer = imgWidth1 - maxWidth1
                    Dim deltaHeight1 As Integer = imgHeight1 - maxHeight1
                    Dim scaleFactor1 As Double

                    If deltaHeight1 > deltaWidth1 Then
                        'Scale by the height
                        scaleFactor1 = maxHeight1 / imgHeight1
                    Else
                        'Scale by the Width
                        scaleFactor1 = maxWidth1 / imgWidth1
                    End If

                    imgWidth1 *= scaleFactor1
                    imgHeight1 *= scaleFactor1

                Else


                End If

                Dim objThumbnail As System.Drawing.Bitmap = New Bitmap(imgWidth1, imgHeight1)

                Dim graphicsImage As Graphics = Graphics.FromImage(objThumbnail)
                graphicsImage.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
                graphicsImage.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
                graphicsImage.DrawImage(PictureInfoLarge, 0, 0, imgWidth1, imgHeight1)
                graphicsImage.Dispose()

                objThumbnail.Save(Path1, Imaging.ImageFormat.Jpeg)


                graphicsImage.Dispose()

                PicturePass = DataPath1
                'e.Values("Picture") = DataPath1

                PictureInfoLarge = Nothing
                objThumbnail = Nothing


                Dim PictureInfoSmall = System.Drawing.Image.FromStream(myStream)


                'Get Picture To be Resized small
                Dim maxWidth2 = 350
                Dim maxHeight2 = 350
                'imgHeight, imgWidth As Integer
                'Dim PictureInfo



                Dim imgHeight2 = PictureInfoSmall.Height
                Dim imgWidth2 = PictureInfoSmall.Width

                ' Determine Scaling
                If imgWidth2 >= maxWidth2 Or imgHeight2 >= maxHeight2 Then
                    'Determine what dimension is off by more
                    ' Dim deltaWidth As Integer = imgWidth - maxWidth
                    'Dim deltaHeight As Integer = imgHeight - maxHeight
                    ' Dim scaleFactor As Double
                    Dim deltaWidth2 As Integer = imgWidth2 - maxWidth2
                    Dim deltaHeight2 As Integer = imgHeight2 - maxHeight2
                    Dim scaleFactor2 As Double

                    If deltaHeight2 > deltaWidth2 Then
                        'Scale by the height
                        scaleFactor2 = maxHeight2 / imgHeight2
                    Else
                        'Scale by the Width
                        scaleFactor2 = maxWidth2 / imgWidth2
                    End If

                    imgWidth2 *= scaleFactor2
                    imgHeight2 *= scaleFactor2

                Else

                End If


                Dim objThumbnail2 As System.Drawing.Bitmap = New Bitmap(imgWidth2, imgHeight2)

                Dim graphicsImage2 As Graphics = Graphics.FromImage(objThumbnail2)
                graphicsImage2.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
                graphicsImage2.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
                graphicsImage2.DrawImage(PictureInfoSmall, 0, 0, imgWidth2, imgHeight2)

                objThumbnail2.Save(Path2, Imaging.ImageFormat.Jpeg)

                graphicsImage2.Dispose()

                PictureThumbPass = DataPath2
                'e.Values("PictureThumb") = DataPath2


                myStream.Close()
                myStream.Dispose()

                PictureInfoSmall = Nothing
                objThumbnail2 = Nothing




                Dal.InsertAquariumPortfolio(e.Values("AquariumsID"), e.Values("AquariumPortfolioCategoriesID"), PicturePass, PictureThumbPass, e.Values("PictureTitle"), e.Values("PictureDescription"))


            End If


        ElseIf Not FileUploadPicture.HasFile Then


        End If




    End Sub

    Protected Sub SuperFormAddEditPictures_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles SuperFormAddEditPictures.ItemUpdated

        Response.Redirect("/AccountSettings/AddEditPictures.aspx")

    End Sub

    Protected Sub SuperFormAddEditPictures_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles SuperFormAddEditPictures.ItemUpdating


        Dal.UpdateAquariumPortfolio(e.Keys("AquariumPortfolioID"), e.NewValues("AquariumsID"), e.NewValues("AquariumPortfolioCategoriesID"), e.NewValues("PictureTitle"), e.NewValues("PictureDescription"))


    End Sub

   


End Class

Open in new window

0
Comment
Question by:TheWebGuy38
4 Comments
 
LVL 8

Accepted Solution

by:
crysallus earned 500 total points
Comment Utility
Just a guess, which probably isn't correct...

Do you have different imports on those pages you are getting the error compared to the pages you are not? That may mean it is dealing with a different Image or Control object on different pages, hence the different behaviour.
0
 

Author Comment

by:TheWebGuy38
Comment Utility
Interesting

you were right

I take out "Imports Obout.Grid"

and the error goes away. although I'm using the about grid on almost all my other pages
and I don't have that problem on them. hrmmm
so maybe it's something conflicting with it out that page
0
 
LVL 40

Expert Comment

by:evilrix
Comment Utility
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now