In this example, you will set valid file extensions for files that can be uploaded and scan the files to check to see if they are infected. The upload will be cancelled if a file is infected.
We will subscribe the ValidatingFile event of C1Upload and scan the file being uploaded. For this, we will run an instance of the AVG application and check whether the file is infected or not. Note that for this example we are using AVG 10 (free version - http://www.freeavg.com/?lng=in-en&cmpid=free).
The results of the virus scan are written in a Report.txt which is saved in the Temporary storage of C1Upload.
Next, we will use a StreamReader object to read the Report.txt file and check whether it contains a "Found infections" string. If the string is found, then we will cancel the upload process by calling e.IsValid = False and we will then delete the file being uploaded using File.Delete().
Select View | Code and add the following code to the Default.aspx.cs:
protected void u1_ValidatingFile(object sender, C1.Web.Wijmo.Controls.C1Upload.ValidateFileEventArgs e) { var file = e.UploadedFile; // remove foreach // foreach (C1FileInfo file in C1Upload1.UploadedFiles) try { //validate file // Note: In this arg, "TempFileName" and "FileName" is a read-only property. // you can pass a message in “e.Message” } catch (Exception ex) { //handle exception } }