Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
H Everyone...

In my C# .net desktop application i want to copy text from a text file and want to paste that text into a notepad or MS Word or Word pad .

i use
string.Copy(String str);
to copy the text of that Text file but when open a MS Word or Note Pad or Word Pad ,nothing to be pasted .

how to paste one text into MS Word or Note Pad or Word Pad from VS Test Box ?
Posted

You just need to write the string into text file and store it at desired path. Suppose your data is in string strValue:
C#
string strValue = "your data";

FileStream fs = new FileStream("D:\\test.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(strValue);
sw.Flush();
sw.Close();

this will create a file test.txt in your D drive if it doesn't exist. otherwise it will append. if u don't want to append and create new file everytime, you can just delete before writing.
C#
if (File.Exists("D:\\test.txt");
	File.Delete("D:\\test.txt");


Inclue System.IO namespace.
 
Share this answer
 
Use below code

C#
Clipboard.SetText(txtClipboard.Text);


Also refer Clipboard Copy and Paste with C#[^]
 
Share this answer
 
Comments
krushna chandra jena 10-Nov-12 2:49am    
Thank You very much
Shanalal Kasim 10-Nov-12 2:52am    
Welcome

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