Click here to Skip to main content
15,924,317 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi,
I have a word file.when i am converting .docx/.doc file to text file in a text box. i want separated sentences.

i want in one line only one sentence.

when there is full stop(.) then cursor automatically goes to next line.

i am new in programming.

please give me reply.

[Moved from Comment]
C#
Microsoft.Office.Interop.Word.ApplicationClass wordObject = new Microsoft.Office.Interop.Word.ApplicationClass(); 
object File = txtfilepath.Text; //this is the path 
object nullobject = System.Reflection.Missing.Value; 
Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word._Document docs = wordObject.Documents.Open(ref File, ref nullobject, ref nullobject, ref nullobject, 
   ref nullobject, ref nullobject, ref nullobject, ref nullobject, 
   ref nullobject, ref nullobject, ref nullobject, ref nullobject, 
   ref nullobject, ref nullobject, ref nullobject, ref nullobject); 
docs.ActiveWindow.Selection.WholeStory(); 
docs.ActiveWindow.Selection.Copy(); 
IDataObject data = Clipboard.GetDataObject(); 
txtshowfile.Text = data.GetData(DataFormats.Text).ToString(); 
string name = txtshowfile.Text; 
name = name.Replace('.','\n'); 
docs.Close(ref nullobject,ref nullobject,ref nullobject); 
wordobject.Quit(ref nullobject,ref nullobject,ref nullobject);
Posted
Updated 4-Jan-12 8:42am
v3
Comments
bbirajdar 4-Jan-12 8:27am    
Tell us what have you done till now. If possible, post the code snippet..
mayankshrivastava 4-Jan-12 8:51am    
Microsoft.Office.Interop.Word.ApplicationClass wordObject=new Microsoft.Office.Interop.Word.ApplicationClass();
object File=txtfilepath.Text; //this is the path
object nullobject=System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word._Document docs = wordObject.Documents.Open(ref File, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject);
docs.ActiveWindow.Selection.WholeStory();
docs.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
txtshowfile.Text = data.GetData(DataFormats.Text).ToString();
string name = txtshowfile.Text;
name = name.Replace('.','\n');
docs.Close(ref nullobject,ref nullobject,ref nullobject);
wordobject.Quit(ref nullobject,ref nullobject,ref nullobject);
i am open word file in text box.
it works fine.
but now i want if in docx file there are lot of sentences than i want these sentences in a particular line.

I am not getting your problem..,
see the below code this may helps you

C#
string name = "Peter.Ronald.Garner.Simon.Liisha.Lori";
           name=name.Replace('.','\n');


BTW "name" contains your data.
 
Share this answer
 
Comments
mayankshrivastava 4-Jan-12 8:52am    
dats my code-
Microsoft.Office.Interop.Word.ApplicationClass wordObject=new Microsoft.Office.Interop.Word.ApplicationClass(); object File=txtfilepath.Text; //this is the path object nullobject=System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word._Document docs = wordObject.Documents.Open(ref File, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject, ref nullobject); docs.ActiveWindow.Selection.WholeStory(); docs.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); txtshowfile.Text = data.GetData(DataFormats.Text).ToString(); string name = txtshowfile.Text; name = name.Replace('.','\n'); docs.Close(ref nullobject,ref nullobject,ref nullobject); wordobject.Quit(ref nullobject,ref nullobject,ref nullobject);

i am open word file in text box. it works fine. but now i want if in .docx file there are lot of sentences than i want these sentences in a particular line in same text box.
mayankshrivastava 4-Jan-12 9:43am    
i am using this its correct but its not working in text box.
Rajesh Anuhya 4-Jan-12 9:44am    
is your textbox is multilined??
mayankshrivastava 4-Jan-12 9:45am    
yes..
mayankshrivastava 4-Jan-12 9:55am    
any other ideas..mr. rajesh ?
If you don't care about any instances of a period that is not used to end a sentence. (i.e. Mr., Mrs., i.e. ...)
then you should just be able to replace all instances of periods in your document with a period-newline combination.
C#
doc = doc.replace( ".", "." + Environment.NewLine );

If you write this resulting string to a textfile, you should have your one sentence per line done.

NOTE:
You won't see the results properly in your Textbox unless you turn the Multiline property to true.
 
Share this answer
 
Comments
Wendelius 4-Jan-12 16:16pm    
+5
Wonde Tadesse 4-Jan-12 17:10pm    
5+
What Marcus and Rajesh suggested is the correct way to go. Also consider simplifying your code. For example the usage of clipboard and defining all optional parameters is unnecessary. The code could look something like (may contain a lot of typos):
C#
object File = txtfilepath.Text; //this is the path;
object nullobject = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word._Document doc = wordobject.Documents.Open(ref File);
doc.ActiveWindow.Selection.WholeStory();
string allText = doc.ActiveWindow.Selection.Text;
doc.Close(ref nullobject, ref nullobject, ref nullobject);
wordobject.Quit();
allText = allText.Replace(".", "." + Environment.NewLine);

Also add proper try..catch blocks to handle possible exceptions.
 
Share this answer
 
v3

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