上传文件病毒扫描

上传文件病毒扫描

本文介绍了上传文件病毒扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传文件病毒扫描



我尝试过:



i want to upload a file virus scanning

What I have tried:

public void scanfile()
   {
       string c;
           bool IsValid = true;
       //foreach (FileInfo file in fileuploadExcel.Unload)
       //{
       try
       {
           //do av check here
           Process myProcess = new Process();
           FileUpload1.SaveAs(Server.MapPath("~\\uploadphoto\\") + FileUpload1.FileName);
           //address of command line virus scan exe
           myProcess.StartInfo.FileName = Server.MapPath("~\\AVG10\\avgscanx.exe");


           string path = '"' + "" + Server.MapPath("~\\uploadphoto\\") + "" + FileUpload1.FileName + "" + '"';
           string report = '"' + "" + Server.MapPath("~\\uploadphoto\\Report.txt") + "" + '"';
           string myprocarg = "/SCAN=" + path + " /REPORT=" + report;
           //" /REPORT=C:\\Upload\\Temp\\Report.txt";
           myProcess.StartInfo.Arguments = myprocarg;
           myProcess.StartInfo.UseShellExecute = false;
           myProcess.StartInfo.RedirectStandardOutput = true;

           myProcess.Start();
           myProcess.WaitForExit(); //wait for the scan to complete
                                    //add some time for report to be written to file
           int j = 0;
           int y = 0;
           for (j = 0; j <= 1000000; j++)
           {
               y = y + 1;
           }
           //Get a StreamReader class that can be used to read the file
           StreamReader objStreamReader = default(StreamReader);
           objStreamReader = File.OpenText(Server.MapPath("~\\VirusScan\\Report.txt"));
           String reportVerbose = objStreamReader.ReadToEnd().Trim();
           if (reportVerbose.Length > 0 && !reportVerbose.Contains("Found infections    :    0"))
           {
               IsValid = false;
               File.Delete(Server.MapPath("~\\VirusScan\\temp\\") + "" + FileUpload1.FileName);
           }
           objStreamReader.Close();
           if (IsValid)
           {
               try
               {
                   if (!Directory.Exists(Server.MapPath("~/DataFiles/")))
                       Directory.CreateDirectory(Server.MapPath("~/DataFiles/"));
                   if (!File.Exists(Server.MapPath("~/DataFiles/" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName))))
                   {
                       FileUpload1.SaveAs(Server.MapPath("~/DataFiles/") + FileUpload1.FileName);
                   }
                   else
                   {
                       try
                       {
                           File.Delete(Server.MapPath("~/DataFiles/" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)));
                           FileUpload1.SaveAs(Server.MapPath("~/DataFiles/") + FileUpload1.FileName);
                       }
                       catch (System.IO.IOException)
                       {

                       }
                   }
               }
               catch (System.IO.IOException)
               {

               }

           }
       }
       catch (System.IO.IOException)
       {

       }

推荐答案


这篇关于上传文件病毒扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:51