To achieve this, we can use the following namespace: "System.IO". Here is a custom code snippet, where the single parameter is the filePath parameter which is for accepting file path to validate size.
- public void ValidateFileSize(string filePath) {
- if (!File.Exists(filePath)) {
- //Throw error if file not found
- }
- FileInfo fileInfo = new FileInfo(filePath);
- //Validate Length
- if (fileInfo.Length / 1048 > 20) {
- //Throw error if file size is larger than your default/set size.
- }
- }

Hamid KhanPosted Sep 4, 2019, 2:08 AM
Good example in sort way...…….Thanks