I want to write an application that can detect whether a value in CSS/HTML file has changed or not, how can I do that ?

Please post example code / import as much as possible. Tkq

For starters you would need to have a benchmark or base value to establish against the file to be tested.

From there you would basically have to do a line by line string by string (or char by char) comparison between the two files to determine changes between the base value and the current file (of course you can try to determine if the file is identical first but file size and creation date/time are not always good identifiers of sameness).

As for posting example code... sorry, don't have any pre-made and too tired to try to write it for you right now :twisted: but based on the information above you should be able to make a few educated steps in the right direction for what you're looking to do.

Don't be afraid to do some research on file reading to figure out how that works :)

You could, yes, but the principle remains the same... you need a benchmark file to compare to item by item in order to determine if a change has occurred.

Can I just use a variable to store the value at first then later check the value again, compare to the variable ?

Not sure what you mean there... Your initial question was how to check for a change in the file. In order to do that you need to have the original file vs the file being checked. Only other way that would be quicker and easier is if you had a stored table of checksum values for your files and compared against that.

I have done a simple code for you because i am new to C# as well so just took this question as a task:

public void Detect_changes_in_webpage()
        {
            String url,output,compare_output;
            Console.WriteLine("Enter the URL:");
            url = Console.ReadLine();

            Uri uri = new Uri(url);

            WebRequest RQ = WebRequest.Create(uri);
            WebResponse RE = RQ.GetResponse();
            Stream STR = RE.GetResponseStream();
 
            StreamReader SR = new StreamReader(STR);

            output = SR.ReadToEnd();

            Console.Write("\n The output of the webpage is given below:");

            Console.Write(output);

            compare_output = output;

            while (compare_output == output)
            { 
            

            //Just wait for the webpage to change

                Thread.Sleep(5000);
 
                output = SR.ReadToEnd();

                Console.WriteLine("\nChecking... Web Page not updated");
                
            
            }

            Console.WriteLine("\nThe webpage has changed");

        
        }

Ofcourse you have to add main method and put the method in the class etc.

Edited 6 Years Ago by Software guy: Missed few lines of code

I guess I should add another request and response in the "while" part to get it work. Anw, tkq

Edited 6 Years Ago by tungnk1993: n/a

Yes you have to add few lines, here is the modified code, hope this helps:

public void Detect_changes_in_webpage()
        {
            String url,output,compare_output;
            int result_comp=0;
            Console.WriteLine("Enter the URL:");
            url = Console.ReadLine();

            Uri uri = new Uri(url);

            WebRequest RQ = WebRequest.Create(uri);
            WebResponse RE = RQ.GetResponse();
            Stream STR = RE.GetResponseStream();
 
            StreamReader SR = new StreamReader(STR);

            output = SR.ReadToEnd();

         //   Console.Write("\n The output of the webpage is given below:");

           // Console.Write("{0}",output);

            
            compare_output = output;
            
 
            while (result_comp < 2 || result_comp > -2)
            {
                
                //Just wait for the webpage to change
                RQ = WebRequest.Create(uri);
                RE = RQ.GetResponse();
                STR = RE.GetResponseStream();

                SR = new StreamReader(STR);

                Thread.Sleep(5000);
                output = SR.ReadToEnd();
                         
                Console.WriteLine("\nChecking... Web Page not updated");
                Console.WriteLine("{0}", result_comp);

                result_comp = String.Compare(compare_output, output);
            
            }

            Console.WriteLine("\nThe webpage has changed");
            Console.WriteLine("{0}", result_comp);

        
        }
This question has already been answered. Start a new discussion instead.