I created a file import method. I would like to know how to limit the file to the server.
I created a file import method. I would like to know how to limit the file to the server.
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>
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.