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 8485061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:32:26+00:00 2026-06-10T20:32:26+00:00

Our classic ASP application uses one .aspx page to upload an image for each

  • 0

Our classic ASP application uses one .aspx page to upload an image for each client.
I’m not familiar with ASP.net, so this page is difficult for me to understand.

<html>
<head>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <script language="VB" RunAt="Server">

        Sub Page_Load(Sender As Object, e As EventArgs)
            Span1.InnerHtml = "You may not upload a file larger than 250 Kilobytes. Your image must be in JPG format.<br />Please crop your image to 400 pixels high and 300 pixels wide, so that no distortion will occur when displayed.<br /><br />"
        End Sub

        Sub Upload_Click(Sender As Object, e As EventArgs)
            Dim DistributorID As Integer
            DistributorID = request.QueryString("distID")

            ' Display properties of the uploaded file

            'Let us recover only the file name from its fully qualified path at client 

            Dim strFileName As String
            strFileName = MyFile.PostedFile.FileName
            Dim c As String = CStr(DistributorID) & "." & split(System.IO.Path.GetFileName(strFileName), ".")(1) ' The file name is the distid + the extension

            'Let us Save uploaded file to server 
            If LCase(Split(System.IO.Path.GetFileName(strFileName), ".")(0)) = "" Then
                Span1.InnerHtml = "Please select a Photo.<br /><br />"
            End If

            If LCase(Split(System.IO.Path.GetFileName(strFileName), ".")(1)) <> "jpg" Then
                Span1.InnerHtml = "Invalid file format."
            Else

                If MyFile.PostedFile.ContentLength < 250000 Then
                    MyFile.PostedFile.SaveAs(ConfigurationSettings.AppSettings("DistImagePath") + c)
                    Span1.InnerHtml = "Your file imported sucessfully to the server.<br /><br />"
                Else
                    Span1.InnerHtml = "Your file is too large to import.<br /><br />"
                End If
            End If

        End Sub

    </script>
</head>
<body>      
    <span id="Span1" style="color:Red;" RunAt="Server" />                   
    <form method="Post" enctype="Multipart/Form-Data" RunAt="Server" class="stdform stdform2">
        &nbsp;&nbsp;Select New Photo: <br />
        &nbsp;<input id="MyFile" type="File" runat="Server" size="40" /><br /><br />            
        <span style="padding-left:25px;">
            <button type="Submit" value="Import" OnServerclick="Upload_Click" RunAt="Server">Upload New Photo</button>
        </span>
    </form>
</body>

If no file is selected and the Upload New Photo button is pressed, I get a
“Index was outside the bounds of the array.” error

How can I fix this page to not attempt to upload a photo if they haven’t selected one?

  • 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-06-10T20:32:27+00:00Added an answer on June 10, 2026 at 8:32 pm

    You can enclose everything in an IF as so:

    IF MyFile.PostedFile.ContentLength>0 Then 'User selected a file
    
       'All your code here
    Else
        Span1.InnerHtml = "Your did not select a file.<br /><br />"
    End IF
    

    Full code:

     Sub Upload_Click(Sender As Object, e As EventArgs)
        IF MyFile.PostedFile.ContentLength>0  Then   
            Dim DistributorID As Integer
            DistributorID = request.QueryString("distID")
    
            ' Display properties of the uploaded file
    
            'Let us recover only the file name from its fully qualified path at client 
    
            Dim strFileName As String
            strFileName = MyFile.PostedFile.FileName
            Dim c As String = CStr(DistributorID) & "." & split(System.IO.Path.GetFileName(strFileName), ".")(1) ' The file name is the distid + the extension
    
            'Let us Save uploaded file to server 
            If LCase(Split(System.IO.Path.GetFileName(strFileName), ".")(0)) = "" Then
                Span1.InnerHtml = "Please select a Photo.<br /><br />"
            End If
    
            If LCase(Split(System.IO.Path.GetFileName(strFileName), ".")(1)) <> "jpg" Then
                Span1.InnerHtml = "Invalid file format."
            Else
    
                If MyFile.PostedFile.ContentLength < 250000 Then
                    MyFile.PostedFile.SaveAs(ConfigurationSettings.AppSettings("DistImagePath") + c)
                    Span1.InnerHtml = "Your file imported sucessfully to the server.<br /><br />"
                Else
                    Span1.InnerHtml = "Your file is too large to import.<br /><br />"
                End If
            End If
         Else
                Span1.InnerHtml = "Your did not select a file.<br /><br />"
         End IF
    
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a legacy classic ASP interface between our client application and the
my application is developed on classic asp, but also uses asp.net as I am
We currently have a classic ASP.NET web application which serves as our API. It
We have a website that uses Classic ASP. Part of our release process substitutes
We have a Com+ VB6 DLL used in our asp classic application. After upgrading
We have a classic ASP page that is instantiating a .Net object through a
We are in the process of migrating an ASP Classic/ASP.NET application from IIS 6
I have a classic ASP application currently secured using ASP.NET Forms Authentication running on
Let me qualify this question. I'm working on a classic ASP.NET application (Web Forms)
In a previous job we had a classic ASP application that no one wanted

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.