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)) {
-
- }
- FileInfo fileInfo = new FileInfo(filePath);
-
- if (fileInfo.Length / 1048 > 20) {
-
- }
- }
Related tutorial