Limit file size

0

I created a file import method. I would like to know how to limit the file to the server.

    
asked by anonymous 19.02.2016 / 03:24

2 answers

5

One of the possibilities would be to add this to web.config :

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="10000" />
    </system.web>
</configuration>

You can also configure this in IIS:

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="10000" />
        </requestFiltering>
    </security>
</system.webServer>
    
19.02.2016 / 08:50
2

Good for you to be able to limit the size of the file uploaded to the server, you only have to use this function:

FileInfo fileInfo = new FileInfo(@"c:\arquivo.txt");
Console.WriteLine(fileInfo.Length);

This function has the purpose of returning the file size, After taking the size of the file to be uploaded, you check: if the size is suitable upa, otherwise no upa.

    
19.02.2016 / 04:45