paste to notepad

G

gordon

Hi

I have a datagrid view that i allow a user to select some rows from. I give
the user two options - first to copy to clipboard, and second, to open
notepad and paste the rows there.

I have code for the first (copy to clipboard) and i can open the notepad,
but dont know how to paste the clipboard contents to the notepad.

Any assistance appreciated.

doug
 
M

Marc Gravell

Two options really; first is to use PInvoke to identify and activate
the notepad window, then SendKeys (either Ctrl+V, or the actual text);
the other is to copy IE; write a temp file somewhere, start notepad
with that file as a parameter, wait a few seconds (for notepad to load
the file), then kill the temp file.

Latter is simpler in that it doesn't involve Win32 API calls; former is
a little cleaner in that it doesn't use files.

Marc
 
G

gordon

Thanks Marc,

I have tried SendKeys.Send("^V") but this doesn't seem to work for pasting
in notepad. Maybe because of focus or something.

Could you explain the "copy IE; write a temp file somewhere, start notepad"
process more - even with some sample code???

Thanks

Doug
 
P

Paul E Collins

gordon said:
Could you explain the "copy IE; write a temp file
somewhere, start notepad" process more - even
with some sample code???

Head code, untested:

using System.Diagnostics;
using System.IO;
....
string file = Path.GetTempFileName;
using (StreamWriter w = new StreamWriter(file))
{
w.Write(...); // the contents of your file
w.Close();
}
Process.Start("notepad.exe", file);

Eq.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top