Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Limiting the size of an uploaded file

Limiting the size of an uploaded file

Limiting the size of an uploaded file


I have the following script to upload files:

CODE -->

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        If FileUpload1.HasFile Then
                FileUpload1.SaveAs("C:\Uploads\" & _
                Label1.Text = "File name: " & _
                     FileUpload1.PostedFile.FileName & "<br>" & _
                     "File Size: " & _
                     FileUpload1.PostedFile.ContentLength & "<br>" & _
                     "Content type: " & _
                     FileUpload1.PostedFile.ContentType & "<br>" & _
                     "Location Saved: C:\Uploads\" & _
            Catch ex As Exception
                Label1.Text = "ERROR: " & ex.Message.ToString()
            End Try
        Else : Label1.Text = "You have not specified a file."
        End If

        Label1.Attributes.Add("style", "display:block")
    End Sub 

It seems to work OK. I also aim to limit the size of files that can be uploaded and use this Web1.config file (so I have two Web.config files: the other one has my database connection details in it):

CODE -->

<?xml version="1.0"?>


    <compilation debug="false" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />

  <authentication mode="Forms">

      <deny users="?" />
      <allow users="*" />

    <forms loginUrl="upload.aspx"

  <!--Limit file size to 500KB-->

    <httpRuntime maxRequestLength="524288"/>


Is my upload.aspx or upload.aspx.vb file able to 'see' this Web.config file because I haven't referenced it in either of those two aspx files?

I wonder also if it may be worth notifying the user if he tries to go over the file size limit, but I am not sure how to do that.

Many thanks!

RE: Limiting the size of an uploaded file

Many thanks for that, jbenson001

There are lots of links to other links there, too. Lots of reading to get through bigsmile


RE: Limiting the size of an uploaded file

Glad to help

Shouldn't be too bad, lots of the links point to the same thing so it should be a short read.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close