I used
System.Diagnostics.Process.Start _
("D:\somepath\somefile.txt")
to open a txt file. My question is how to make some entry when the file is being opened?
say for example if I click on a buttom in my project, it opens the txt file and enter "123abc
on the txt file
AlanPosted Jul 10, 2007, 11:44 AM
If you want the text to appear after you've opened the file, then I'd check out the SendKeys class:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
The application here is, of course, your default text editor (probably notepad.exe) rather than the textfile itself.
You'll need to force the focus onto the text editor window first and the easiest way to do that is by calling the Win32 API function FindWindow. This link shows how to use this from both VB.Net and C#:
http://pinvoke.net/default.aspx/user32/FindWindow.html
To use the DllImport attribute, you'll need this line at the top of your program:
Imports System.Runtime.InteropServices
Of course, if you want to write the text to the file before you open it, you can simply use a StreamWriter to do this, close the file and then reopen using the Process.Start method.