Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3231680
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:04:24+00:00 2026-05-17T17:04:24+00:00

I was doing a test to upload pictures and i found out that when

  • 0

I was doing a test to upload pictures and i found out that when i upload pictures more than 2000px the webpage turn to be slow. I want users to upload pics with size not more than 600px and height 700px.

Imports System.Data
Imports System.IO
Imports System.Data.SqlClient

Partial Class PhotoAdmin_Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    UserIdValue.Text = Membership.GetUser().ProviderUserKey.ToString()
    cannotUploadImageMessage.Visible = False

End Sub


Protected Sub dvPictureInsert_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvPictureInsert.ItemInserted
    'If the record was successfully inserted, save the picture
    If e.AffectedRows > 0 Then
        'Determine the maximum pictureID for this user
        Dim results As DataView =
            CType(maxPictureIDDataSource.Select(DataSourceSelectArguments.Empty), 
                DataView)

        Dim pictureIDJustAdded As Integer = CType(results(0)(0), Integer)

        'Reference the FileUpload control
        Dim imageUpload As FileUpload =
            CType(dvPictureInsert.FindControl("imageUpload"), FileUpload)

        If imageUpload.HasFile Then
            Dim baseDirectory As String = Server.MapPath("~/UploadedImages/")

            imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg")
        End If

    End If

    If e.Exception Is Nothing Then

        ' Use the AffectedRows property to determine whether the
        ' record was inserted. Sometimes an error might occur that 
        ' does not raise an exception, but prevents the insert
        ' operation from completing.
        If e.AffectedRows = 1 Then

            MessageLabel.Text = "Record inserted successfully."

        Else

            MessageLabel.Text = "An error occurred during the insert operation."

            ' Use the KeepInInsertMode property to remain in insert mode
            ' when an error occurs during the insert operation.
            e.KeepInInsertMode = True

        End If

    Else

        ' Insert the code to handle the exception.
        MessageLabel.Text = e.Exception.Message

        ' Use the ExceptionHandled property to indicate that the 
        ' exception has already been handled.
        e.ExceptionHandled = True
        e.KeepInInsertMode = True

    End If

End Sub



Protected Sub dvPictureInsert_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvPictureInsert.ItemInserting
    Dim cancelInsert As Boolean = False


    Dim imageUpload As FileUpload =
        CType(dvPictureInsert.FindControl("imageUpload"), FileUpload)

    If Not imageUpload.HasFile Then
        cancelInsert = True
    Else
        If Not imageUpload.FileName.ToUpper().EndsWith(".JPG") Then
            cancelInsert = True 'Invalid image file!

        End If
    End If

    If cancelInsert Then
        e.Cancel = True
        cannotUploadImageMessage.Visible = True
    End If

    'Set the UserId value to the currently logged on user's ID
    e.Values("UserId") = Membership.GetUser().ProviderUserKey

    'Set the UploadedOn value to the current date/time
    e.Values("UploadedOn") = DateTime.Now
End Sub

Protected Sub gvPictures_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles gvPictures.RowDeleted
    Dim baseDirectory As String = Server.MapPath("~/UploadedImages/")
    Dim fileName As String = baseDirectory &
        e.Keys("PictureID") & ".jpg"
    File.Delete(fileName)
End Sub

Protected Sub gvPictures_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvPictures.RowUpdating
    e.NewValues("UserId") = Membership.GetUser().ProviderUserKey
End Sub

End Class

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:04:25+00:00Added an answer on May 17, 2026 at 5:04 pm

    Sorry if my vb is wrong as im a c# guy!! but I hope this should give you a guidance. I do something similar in c#. Good luck

    Protected Sub dvPictureInsert_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvPictureInsert.ItemInserting
        Dim cancelInsert As Boolean = False
    
    
        Dim imageUpload As FileUpload =
            CType(dvPictureInsert.FindControl("imageUpload"), FileUpload)
    
        If Not imageUpload.HasFile Then
            cancelInsert = True
        Else
            If Not imageUpload.FileName.ToUpper().EndsWith(".JPG") Then
                cancelInsert = True 'Invalid image file!
            Else
                Dim image As System.Drawing.Image = 
                    System.Drawing.Image.FromStream(imageUpload.PostedFile.InputStream)
                If image.Width > 600 Or image.Height > 700 Then
                   cancelInsert = True
                End If
            End If
        End If
    
        //etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking in to doing some test driven development for one of
I am doing some simple sanity validation on various types. The current test I'm
I use Assert.Fail a lot when doing TDD. I'm usually working on one test
What does this mean exactly? I'm doing something like this: File.Copy(@\\foo\bar\baz.txt, @c:\test\baz.txt); MSDN doesn't
When doing case-insensitive comparisons, is it more efficient to convert the string to upper
When doing TDD , how to tell that's enough tests for this class /
I've created an HttpModule in ASP.NET to allow users to upload large files. I
Currently doing a test plan for a system. May I know what are the
I have several mysql tables in a database. Currently I am doing finishing test
I'm doing a simple test of Code Contracts. The following code is in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.