I am looking for a solution in c# or generally in any language which will do the following:
1) Let say you have an opened notepad and have write something inside. File is unsaved.
2) Via the program you will create save as "foo.txt" the notepad file and then close it.
In C# you can get process by name or id so you can have the process. But then how to make the process to save as and then close? Or maybe at least get the data of notepad and then i can save it via SystemIO. But the problem is how from process get the data of the process and in my particular example get the notepad text (remember text is unsaved so no way to recover it from a path).
Thanks a lot.
As the others have said, it's not the best approach by far...
...but sure, you can actually do that.
Here's an example that retrieves the contents of all open Notepad instances and spits them out in the Console:
This approach is specific to Notepad (it's not a generic approach to any application). We're using FindWindowEx() to find a child window called "Edit", that is a direct child of the main application window. You can use tools like Spy++ to figure out the window hierarchy of an application to help solve problems like these. In situations where the target window is buried more deeply, or may be one of many windows of the same type at a particular level, you may need to use several other APIs to get a handle to the correct window. This is a complex topic and there are several other low level API approaches that can be used.