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

  • SEARCH
  • Home
  • 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 8563805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:03:00+00:00 2026-06-11T17:03:00+00:00

I Had a file upload control I want that file will attach only when

  • 0

I Had a file upload control I want that file will attach only when it is below under some Memory Limit (8 Mb). I get the file size using Ajax and call it on the onchange event. But I am not able to restrict the attachment of files. Can any one Help me ?

This is the example code

function a(obj) {
    if ($(obj).val() != '') {
        var request;
        var flag = false;
        request = $.ajax({
            type: "POST",
            url: 'CheckFileSize.aspx',
            data: "search=" + $(obj).val(),
            success: function (size) {
                if (parseFloat(size) < 8192) {
                    flag = true;
                }
                if (!flag) {
                    alert('File size is greater then 8 MB. The size of the file is ' + (parseFloat(size)) / 1024 + ' MB');

//Doing something that restrict user from upload enter code here
$(obj).val(null);
}
return flag;
}
});
}
return false;
}

  • 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-11T17:03:01+00:00Added an answer on June 11, 2026 at 5:03 pm

    In your server-side method where you process the uploaded file, add this code:

            if (myFileUploadControl.HasFile)
            {
                    int maxSize = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MaxImageSize"));     //MaxImageSize specified in web.config file to make it easy to change.
    
                    int imageSize = myFileUploadControl.PostedFile.ContentLength;
                    if (imageSize > maxSize)
                    {
                        string uploadImageError = "The selected file exceeds the maximum allowed size (" + maxSize / 1000 + "k)";  // Message to display to user.
                    }
                    else
                    {
    // Code to process the file here.
                    }
            }
    

    Adding the following to the system.web section of the web.config file will also prevent over-large uploads from being accepted.

    <!-- set max upload to 25 MB -->
    <httpRuntime executionTimeout="300" maxRequestLength="25000"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a file upload that was uploading to a folder in the web
For some reason, I'm unable to upload a file with the <asp:FileUpload /> control.
I had a FileUpload control earlier to upload each file individually in the database.
I want to modify my existing folder structure. I had a file tree that
I had created a zip file (together with directory) under Windows as follow (Code
I'm practicing some file upload with PHP and I was uploading a file numerous
I am using ajax toolkit asyncFileUpload control I had problem that my server side
im trying to use a file upload control from the obout control library, i
I am working on a file upload system which will store individual parts of
I have a HTML form ( upload.htm ) with a HTML file upload control

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.