Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<location path="RegistrationPage2.aspx">
        <system.web>
            <httpRuntime executionTimeout="240" maxRequestLength="2097152" />
              </system.web>
       </location>





Here how to access maxrequest length value into code behind file for display the warning message "The maximum file size is 2MB!".


Please give the code to display the warning message if the file size is above 2MB.
Posted

1 solution

C#
var section = HttpContext.Current.GetSection("system.web/httpRuntime") as System.Web.Configuration.HttpRuntimeSection;


will get you httpRuntime settings for currently executing page.

C#
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Default.aspx");
HttpRuntimeSection o = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection;


will get you settings for a given virtual path.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900