1

I am trying to build an Application where contents of a text file automatically appear in a RichTextbox as soon the user modifies the notepad file.

Currently its working fine when user saves the notepad file. but i want it to be automatically saved every second.

Azaz Khan
  • 106
  • 1
  • 6
  • 1
    I am pretty sure this is impossible to do the way you described. If you want to do this you must either interface with an editor that supports this, such as Notepad++, or use a custom built-in editor. Otherwise you must wait for the actual file to be changed. Windows Notepad does not expose it's text content to other programs. – d3dave Jun 07 '15 at 09:25
  • 1
    It's possible to read the text from Notepad: http://stackoverflow.com/q/7740379/395718 – Dialecticus Jun 07 '15 at 09:30
  • 2
    You can try to send Ctrl+S to notepad window. – Ondra Jun 07 '15 at 10:17
  • Was my answer useful Azaz? – Thiago Avelino Jun 08 '15 at 23:25

2 Answers2

0

Azaz, you can use a Timer event for every second, then trigger the method to save the notepad file:

See an example:

using System.Timers;    
public class Program{

            private static Timer aTimer;

        public static void Main(string[] args){
            // Create a timer with a one second interval.
            aTimer = new System.Timers.Timer(1000);
            // Hook up the Elapsed event for the timer. 
            aTimer.Elapsed += OnTimedEvent;
            aTimer.Enabled = true;

            Console.WriteLine("Press the Enter key to exit the program... ");
            Console.ReadLine();
            Console.WriteLine("Terminating the application...");
        }
        private static void OnTimedEvent(Object source, ElapsedEventArgs e) {
            //Call Save NotePad File
            Console.WriteLine("The Notepad files was saved. Elapsed event was raised at {0}", e.SignalTime);
        }


    }
Thiago Avelino
  • 818
  • 6
  • 7
0

Thanks Everyone! i solved that by sending a CTRL + S keystroke to the notepad process. @Ondra, yes i did the same way.

Azaz Khan
  • 106
  • 1
  • 6