Click here to Skip to main content
15,867,977 members
Please Sign up or sign in to vote.
2.80/5 (5 votes)
See more:
Dear All,
i am working on windows application and i need to copy all the text from text box to notepad file. i can copy all the text from text box to clipboard but now how can i copy this clipboard text to Notepad file.

Any kind of link, suggestion and specially expert advice would be highly appreciated.

Thanks & Regards,
Balkrishna Raut
Posted
Comments
johannesnestler 13-Apr-11 7:41am    
so you just want to write a textfile?
Toli Cuturicu 13-Apr-11 8:01am    
Why? (seriously, why?)
If you tell us your reasons, we may provide better answers.

I don't recommend doing anything like that.

However, if you insist, you need to do the following. Use Windows API SendInput via P/Invoke, activate Notepad and simulate Ctrl+V keyboard press using SendInput.

—SA
 
Share this answer
 
Comments
Pong D. Panda 13-Apr-11 7:34am    
Maybe he's trying to do a keylogger!
Sergey Alexandrovich Kryukov 13-Apr-11 7:50am    
Key logger is the opposite I guess -- a global Hook.
--SA
You can simply do this :

C#
File.AppendAllText(@"C:\MyNotepadFile.txt",Clipboard.GetText());


The best thing about this method is that, even if the file doesn't exist, it will create one.

If want to overwrite the content, you can use this :
C#
File.WriteAllText(@"C:\MyNotepadFile.txt",ClipBoard.GetText());
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 13-Apr-11 7:52am    
It does nothing to Notepad...
I think this Notepad stuff is nonsense, nothing that OP really wants.
--SA
Tarun.K.S 13-Apr-11 7:54am    
Lol! but that's what OP wants!
Sergey Alexandrovich Kryukov 13-Apr-11 7:59am    
OP does not know that or would not tell us. :-)
--SA
Tarun.K.S 13-Apr-11 8:10am    
I think he does not know!
BobJanova 13-Apr-11 8:01am    
It's what he says he wants, not the same thing ;) ... there seem to be a lot of those questions today.
What you appear to want is to write the contents of a text box to a text file ('Notepad file' = plain text). The clipboard is an an irrelevant distraction.

File.WriteAllText(@"C:\MyNotepadFile.txt", myTextBox.Text);

(thanks to other posters for reminding me of that method)

You can then shell the file using Process.Start if you want to have it open in Notepad. But I have no idea why you would want to do that, since the user can see the content in your textbox already.
 
Share this answer
 
Try this,
IO.File.WriteAllText("c:\test.txt", Clipboard.GetText());
 
Share this answer
 
v2
Comments
Prerak Patel 13-Apr-11 7:37am    
How about IO.File.WriteAllText("c:\test.txt", Clipboard.GetText())?
Toniyo Jackson 13-Apr-11 7:40am    
Yeah. Its good. :thunbsup:
Tarun.K.S 13-Apr-11 7:56am    
You should have written it as answer!
Toniyo Jackson 13-Apr-11 7:57am    
Yeah. Done
Thanks you all.....



i did it!....


this is what i hv done!...

DataObject m_data = new DataObject();
m_data.SetText(txtSearialKey.Text,TextDataFormat.Text);
File.WriteAllText(Application.StartupPath+"\\Text.txt",m_data.GetText());
Process.Start("notepad.exe", Application.StartupPath + "\\Text.txt");

Steps...
1. Copy all d text.

2. Write all the text into a text file at particular location.

3. Open the Text file.
 
Share this answer
 
Comments
omika 23-Nov-12 1:26am    
hie @meBalkrishna. i Tried this code. thanks a lot. Very Useful Code. but i have another requirement. By using this code clipboard copied text from textbox to notepad. but i need to copy a text from one notepad to other. Please help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900