Crud Operations in a text or html or pdf file?

Execute Directly  u Will Get it.

  class Program
    {
        static void Main(string[] args)
        {
            // Must Be in same sysytem
            string filename = "C:/Users/saikiran/Desktop/sajflkdefkjf.html";
            string[] sa = filename.Split('/').ToArray();
            string fileyouUpload = sa.LastOrDefault();
            string[] filename1 = fileyouUpload.Split('.');
            string sa1 = filename1[0];
            string fileext = Path.GetExtension(fileyouUpload);
            string fileprint = fileext != null ? fileext.ToLower() == ".html" ? "html" :               fileext.ToUpper() == ".pdf" ? "pdf" : fileext.ToUpper() == ".txt" ? "txt" : null : null;
            if (fileprint != null)
            {
                Console.WriteLine("You Uploaded file name is" + sa1 + " Format is" + fileprint);
                string inputString = File.ReadAllText(filename);
               inputString = inputString.ToLower();
                // Skip Words (Replace With Space)
                string[] stripChars = { ";", ",", ".", "-", "_", "^", "(", ")", "[", "]",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\n", "\t", "\r"};
                foreach (string character in stripChars)
                {
                    inputString = inputString.Replace(character, "");
                }
                // Split on spaces into a List of strings
                List<string> wordList = inputString.Split(' ').ToList();

                #region Define and remove stopwords

                string[] stopwords = new string[] { "and", "the", "she", "for", "this", "you", "but" };
                foreach (string word in stopwords)
                {
                    while (wordList.Contains(word))
                    {
                        wordList.Remove(word);
                    }
                }
                #endregion

                #region Word Count

                Dictionary<string, int> dictionary = new Dictionary<string, int>();
                foreach (string word in wordList)
                {
                    if (word.Length >= 3)
                    {
                        if (dictionary.ContainsKey(word))
                        {
                            dictionary[word]++;
                        }
                        else
                        {
                            dictionary[word] = 1;
                        }
                    }
                }
                #endregion

                var sortedDict = (from entry in dictionary orderby entry.Value descending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
                int count = 1;
                Console.WriteLine("---- Most Frequent Terms in the File: " + sa1 + " Are----");
                Console.WriteLine();
                foreach (KeyValuePair<string, int> pair in sortedDict)
                {
                    Console.WriteLine(count + "\t" + pair.Key + "\t" + pair.Value);
                    count++;
                    if (count > 10)
                    {
                        break;
                    }
                }
                Console.ReadKey();
            }
        }
    }

Please Revert with a mail with any quires.

Comments

Popular Posts