C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




how to open rtf file as text file and then read in C#.NET


Posted Date: 21 Jul 2008      Total Responses: 1

Posted By: spoorthi       Member Level: Gold     Points: 1


Hi All,

how to open rtf file as text file and then read in C#.NET

i need to open rtf file as txt file and then read the contents fom the txt file could anyone help me in this

Thank You,
Spoorthi




Responses

Author: Madhavan    21 Jul 2008Member Level: GoldRating:     Points: 6
hi Spoorthi,

try this...(Windows Application)
1. Open a new windows app.
2. Go to Project->Add Reference->Select COM tab->Select Microsoft Word 9.0 Object library and click Ok.
3. Use the following code.
// This is for Rtf to Txt convertion
4. after the convertion u can read the contents from the txt using filestream.

private Word.ApplicationClass MSdoc;
object Unknown = Type.Missing;
private void RTF2TXT(object Source, object Target)
{
//Creating the instance of Word Application
if (MSdoc == null) MSdoc = new Word.ApplicationClass();

try
{
MSdoc.Visible = false;
MSdoc.Documents.Open(ref Source, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown);
MSdoc.Application.Visible = false;
MSdoc.WindowState = Word.WdWindowState.wdWindowStateMinimize;


object format = Word.WdSaveFormat.wdFormatText;

MSdoc.ActiveDocument.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
if (MSdoc != null)
{
MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown);
//WordDoc.Application.Quit(ref Unknown, ref Unknown, ref Unknown);
//MSdoc.Application.Quit(ref Unknown, ref Unknown, ref Unknown);
}
// for closing the application

}

MessageBox.Show("File Converted", "RTF2TXT Convertion");

}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" && textBox2.Text != "")
RTF2TXT(textBox1.Text, textBox2.Text);
else
MessageBox.Show("Enter the File name", "RTF2TXT Convertion");
}

Regards,
Madhavan



Post Reply
You must Sign In to post a response.
Next : how to open rtf file as text fileand then read that txt file C#.NET
Previous : DAtagridview Combobox Send me some windows application C#.net coding
Return to Discussion Forum
Post New Message
Category: Windows

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

masks masks masks

Contact Us    Privacy Policy    Terms Of Use