Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I converted docx file into text file but the problem is that the whole text are written in line by line.

e.g Docx file text.
Hello.How R U?
Fine Thanku.

in converted text file it also come from "Fine" on new line not in continue after ? mark.
Posted
Comments
Sujith Karivelil 24-Feb-15 2:08am    
For your problem their may be many solutions. so if you post your code you will get the exact solution which you want.
Sinisa Hajnal 24-Feb-15 2:10am    
So, you get whole text in a single line or Thanku. gets split into new line and "Fine" remains after question mark? How do you convert? Check the result opening the result text file in Notepad++ with all symbology visible, you can do it in wordpad too. You'll see if there are hidden characters, newlines, tabs etc.
AndrewCharlz 24-Feb-15 6:28am    
\n in the text adds new line

1 solution

I send my Code..
So please give me a solution How to write a text in text file on line after conversion?


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using Microsoft.Office.Interop.Word;
using System.Text;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath(FileUpload1.FileName));
object filename = Server.MapPath(FileUpload1.FileName);
Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
try
{
doc = AC.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 isVisible,ref missing,ref missing,ref missing,ref missing);

TextBox1.Text = doc.Content.Text;

//string txt = TextBox1.Text;
string str = "G:\\test.txt";
string[] lines = {TextBox1.Text};

using (FileStream fs = new FileStream(str, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
foreach (String line in lines)
sw.Write(line + sw.NewLine);
}
}
}
catch (Exception ex)
{}
}
}
 
Share this answer
 

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