-
Notifications
You must be signed in to change notification settings - Fork 0
/
XLSValidator.cs
38 lines (32 loc) · 963 Bytes
/
XLSValidator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.IO;
using NPOI.HSSF.UserModel;
using VerifilerCore;
namespace VerifilerMSLegacy {
/// <summary>
/// This validation step is using the NPOI library which can work
/// both with .xls and .xlsx formats.
///
/// The error code produced by this validation is Error.Corrupted.
/// </summary>
public class XLSValidator : FormatSpecificValidator {
public override int ErrorCode { get; set; } = Error.Corrupted;
public override void Setup() {
Name = "Microsoft Excel .xls files Verification";
RelevantExtensions.Add(".xls");
Enable();
}
public override void ValidateFile(string file) {
FileStream stream = null;
try {
stream = File.Open(file, FileMode.Open, FileAccess.Read);
HSSFWorkbook workbook = new HSSFWorkbook(stream);
} catch (Exception e) {
ReportAsError("File is corrupted: " + file + "; Message: " + e.Message);
GC.Collect();
} finally {
stream?.Close();
}
}
}
}