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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:42:07+00:00 2026-05-14T08:42:07+00:00

In my asp .net project, my main page receives URL as a parameter I

  • 0

In my asp .net project, my main page receives URL as a parameter I need to download internally and then process it. I know that I can use WebClient’s DownloadFile method however I want to avoid malicious user from giving a url to a huge file, which will unnecessary traffic from my server. In order to avoid this, I’m looking for a solution to set maximum file size that DownloadFile will download.

Thank you in advance,

Jack

  • 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-14T08:42:08+00:00Added an answer on May 14, 2026 at 8:42 am

    There is no way to do this ‘cleanly’ without using a flash or silverlight file upload control. The best you can do without using those methods would be to set the maxRequestLength in your web.config file.

    Example:

    <system.web>
        <httpRuntime maxRequestLength="1024"/>
    

    The example above will limit the file size to 1MB. If the user tries to send anything larger they will get an error message stating that the maximum request length has been exceeded. It’s not a pretty message though but if you want you can override the error page in IIS to make it match your site possibly.

    EDIT DUE TO COMMENT:

    So your probably using a couple of methods to do the request to get the file from the URL so I will post 2 possible solutions. First is using the .NET WebClient:

    // This will get the file
    WebClient webClient = new WebClient();
    webClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(DownloadCompleted);
    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
    webClient.DownloadFileAsync(new Uri("http://www.somewhere.com/test.txt"), @"c:\test.txt");
    
    private void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        WebClient webClient = (WebClient)(sender);
        // Cancel download if we are going to download more than we allow
        if (e.TotalBytesToReceive > iMaxNumberOfBytesToAllow)
        {
            webClient.CancelAsync();
        }
    }
    
    private void DownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
    {
        // Do something
    }
    

    The other method was to just do a basic web request before doing the download to check the file size:

    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://www.somewhere.com/test.txt"));
    webRequest.Credentials = CredentialCache.DefaultCredentials;
    HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
    Int64 fileSize = webResponse.ContentLength;
    if (fileSize < iMaxNumberOfBytesToAllow)
    {
        // Download the file
    }
    

    Hopefully one of these solutions help or at least get you on the right path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET project that uses XML Serialization for the main operation for
In my asp.net project I need to print a page with some dynamic content.I
I have an ASP.NET application with a <codeSubDirectories> section in web.config. My main project
I am developing an ASP.NET project with C#, and I wrote a page named
I have an ASP.Net project using AJAX that I am putting on a server
I have an ASP.NET project with outputType library, I need to run the project
I have an ASP.NET MVC project that works fine on my local machine (no
I am having a project with asp.net controls in the .aspx page and Javascript
I have an ASP.NET web project that works perfectly on my computer. However, when
In my asp .net C# project I have a page defualt.aspx on which I

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.