Click here to Skip to main content
11,802,222 members (55,856 online)
Rate this: bad
Please Sign up or sign in to vote.
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 9-Nov-12 20:20pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use below code


Also refer Clipboard Copy and Paste with C#[^]
krushna chandra jena at 10-Nov-12 2:49am
Thank You very much
shanalalkasim at 10-Nov-12 2:52am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You just need to write the string into text file and store it at desired path. Suppose your data is in string strValue:
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);
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.
if (File.Exists("D:\\test.txt");

Inclue System.IO namespace.

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

  Print Answers RSS
0 OriginalGriff 475
1 KrunalRohit 341
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CHill60 195
0 OriginalGriff 2,715
1 Maciej Los 1,900
2 KrunalRohit 1,797
3 CPallini 1,550
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 10 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100