Click here to Skip to main content
15,909,939 members
Home / Discussions / C#
   

C#

 
AnswerRe: Exporting word file to text file Pin
sujithkumarsl22-Apr-06 6:56
sujithkumarsl22-Apr-06 6:56 
hi Sahar
Try this code. I actually found an article from C-Sharp Corner on how to open up a word file in C#. You just have a look on that article, I added to the code a little to meet ur requirement.


//Create Word Application class.
Word.ApplicationClass app = new Word.ApplicationClass();
//file which you need to convert to text file
object fileName = @"Sample.doc";
//to set the source file readonly.
object readOnly = true;
object missing = Type.Missing;
//to make the document visible.
object visible = true;
app.Visible = true;
app.Documents.Open(ref fileName,ref missing,ref readOnly,ref missing,
ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,
ref missing,ref visible,ref missing,ref missing,ref missing,ref missing);
//select the whole text in Word file
app.Selection.SetRange(0,app.Selection.StoryLength);
//get the selected text, the whole word file content.
string text = app.Selection.Text;
//create StreamWriter Object.
System.IO.StreamWriter writer = new System.IO.StreamWriter("YourTextFile.txt");
//split the text in to lines.
string []lines = text.Split(Environment.NewLine.ToCharArray());
//Iterate over each lines and write to file.
foreach(string s in lines)
{
//write a line to file.
writer.WriteLine(s);
}
writer.Flush();
writer.Close();



My small attempt...
QuestionCrystal Reports viewing Pin
pavanabollineni21-Apr-06 20:13
pavanabollineni21-Apr-06 20:13 
AnswerRe: Crystal Reports viewing Pin
Sean8922-Apr-06 14:56
Sean8922-Apr-06 14:56 
QuestionTextBox databinding problem Pin
wasife21-Apr-06 19:47
wasife21-Apr-06 19:47 
AnswerRe: TextBox databinding problem Pin
tvshkaa22-Apr-06 19:45
tvshkaa22-Apr-06 19:45 
GeneralPut a Chatroom in your site! Free Ajax C#.NET Simple Chat Code. Pin
spilafis21-Apr-06 19:07
spilafis21-Apr-06 19:07 
GeneralRe: Put a Chatroom in your site! Free Ajax C#.NET Simple Chat Code. Pin
leppie21-Apr-06 22:20
leppie21-Apr-06 22:20 
Questionmedia encoder Pin
d_onK21-Apr-06 18:02
d_onK21-Apr-06 18:02 
Questionrecording video clips Pin
d_onK21-Apr-06 17:58
d_onK21-Apr-06 17:58 
Question'Access' a protected Access 97 database with Access 2003 Installed Pin
ndavie21-Apr-06 15:07
ndavie21-Apr-06 15:07 
QuestionComparing Images Pin
clickman21-Apr-06 12:41
clickman21-Apr-06 12:41 
AnswerRe: Comparing Images Pin
eclipse2k122-Apr-06 10:42
eclipse2k122-Apr-06 10:42 
QuestionRead strings between delimiters Pin
kani9821-Apr-06 11:28
kani9821-Apr-06 11:28 
AnswerRe: Read strings between delimiters Pin
Ravi Bhavnani21-Apr-06 11:31
professionalRavi Bhavnani21-Apr-06 11:31 
AnswerRe: Read strings between delimiters Pin
Guffa21-Apr-06 12:55
Guffa21-Apr-06 12:55 
AnswerRe: Read strings between delimiters Pin
sujithkumarsl22-Apr-06 16:47
sujithkumarsl22-Apr-06 16:47 
QuestionHaving a max line count in a list control Pin
BambooMoon21-Apr-06 11:25
BambooMoon21-Apr-06 11:25 
AnswerRe: Having a max line count in a list control Pin
Ravi Bhavnani21-Apr-06 11:30
professionalRavi Bhavnani21-Apr-06 11:30 
QuestionObserver Pattern Pin
martin_hughes21-Apr-06 11:07
martin_hughes21-Apr-06 11:07 
AnswerRe: Observer Pattern Pin
Ravi Bhavnani21-Apr-06 11:26
professionalRavi Bhavnani21-Apr-06 11:26 
GeneralRe: Observer Pattern Pin
martin_hughes21-Apr-06 11:51
martin_hughes21-Apr-06 11:51 
General64 bit / IME / WindowsHook problem Pin
Daniel Grunwald21-Apr-06 10:11
Daniel Grunwald21-Apr-06 10:11 
GeneralRe: 64 bit / IME / WindowsHook problem Pin
LongRange.Shooter21-Apr-06 15:02
LongRange.Shooter21-Apr-06 15:02 
GeneralRe: 64 bit / IME / WindowsHook problem Pin
Daniel Grunwald22-Apr-06 2:06
Daniel Grunwald22-Apr-06 2:06 
QuestionSwitching from DG tp DGV !!!???!!!???!!!??? Pin
mrkeivan21-Apr-06 9:44
mrkeivan21-Apr-06 9:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.