コード例 #1
0
        public static List <AnalisisResult> readFolderFiles(string PathURL)
        {
            List <AnalisisResult> AnalisesList = new List <AnalisisResult>();
            string uploadsDirectory            = System.Web.HttpContext.Current.Server.MapPath("/Doc_Uploads ");

            string[]     txt = Directory.GetFiles(@PathURL, "*.txt", SearchOption.AllDirectories);
            StreamReader sr;

            foreach (string name in txt)
            {
                sr = new StreamReader(name);
                AnalisesList.Add(analiseTxt(sr.ReadToEnd()));
                sr.Close();
            }

            string[] doc = Directory.GetFiles(@PathURL, "*.doc", SearchOption.AllDirectories);
            foreach (string name in doc)
            {
                Document document = new Document();
                document.LoadFromFile(name);
                document.SaveToFile(uploadsDirectory + "\\" + "ToText.txt", FileFormat.Txt);

                sr = new StreamReader(uploadsDirectory + "\\" + "ToText.txt");
                AnalisesList.Add(analiseTxt(sr.ReadToEnd()));
                sr.Close();
            }

            string[] htmls       = Directory.GetFiles(@PathURL, "*.html", SearchOption.AllDirectories);
            string   withoutHtml = "";

            foreach (string name in htmls)
            {
                sr          = new StreamReader(name);
                withoutHtml = HtmlRemoval.StripTagsRegexCompiled(sr.ReadToEnd());
                sr.Close();
                AnalisesList.Add(Utilities.analiseTxt(withoutHtml));
            }
            return(AnalisesList);
        }
コード例 #2
0
        protected void analiseBtn_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                Utilities.learn();
                StreamReader sr;
                string       ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName);
                if (ext == ".txt")
                {
                    sr = new StreamReader(FileUpload1.PostedFile.InputStream);
                    AnalisisResult res = Utilities.analiseTxt(sr.ReadToEnd());
                    sr.Close();
                }
                else if (ext == ".doc" || ext == ".docx")
                {
                    string uploadsDirectory = System.Web.HttpContext.Current.Server.MapPath("/Doc_Uploads ");
                    string docPath          = System.Web.HttpContext.Current.Server.MapPath(FileUpload1.PostedFile.FileName);
                    FileUpload1.PostedFile.SaveAs(docPath);
                    Document document = new Document();
                    document.LoadFromFile(docPath);
                    document.SaveToFile(uploadsDirectory + "\\" + "ToText.txt", FileFormat.Txt);

                    sr = new StreamReader(uploadsDirectory + "\\" + "ToText.txt");
                    AnalisisResult res = Utilities.analiseTxt(sr.ReadToEnd());
                    sr.Close();
                }

                else if (ext == ".html")
                {
                    sr = new StreamReader(FileUpload1.PostedFile.InputStream);
                    string withoutHtml = HtmlRemoval.StripTagsRegexCompiled(sr.ReadToEnd());
                    sr.Close();
                    AnalisisResult res = Utilities.analiseTxt(withoutHtml);
                }
            }
        }