Problem with program to convert .doc file into .txt file?
ASP.Net: I have made this program in which it will convert .doc file into .txt file. It works well in my machine. So, I published and try to access it in another machine unit, I tried also in my machine. But it didn't convert the file. What seems to be the problem? Anyone, please help. :/
Alex SmithPosted Sep 2, 2014, 9:50 PM
using System;
using System.Windows.Forms;
using Spire.Doc;
using Spire.Doc.Documents;
namespace tohtml_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Create word document
Document document = new Document();
document.LoadFromFile(@"D:\Work\Stephen\2011.12.05\Sample.doc");
//Save doc file.
document.SaveToFile("Sample.txt", FileFormat.Txt);
//Launching the MS Word file.
WordDocViewer("Sample.txt");
}
private void WordDocViewer(string fileName)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch { }
}
}
}
Edda BrownPosted Sep 2, 2014, 5:55 AM
Hi Yin, you are using word automation in your C# project so a possible reason why its not working on server is because you are missing MS Office on server side which is required in order to use "Microsoft.Office.Interop.Word" reference.
Also I would recommend you to read this MS warning for using automation on server side and as a workaround that does not require MS office you can try this alternative .NET library for word documents like the following:
DocumentModel.Load(FileUpload1.PostedFile.InputStream, LoadOptions.DocDefault).Save("Out.txt", SaveOptions.TxtDefault);
Also from your solution it seems that you are actually creating a PDF file from the .NET so you can try this instead:
DocumentModel.Load(FileUpload1.PostedFile.InputStream, LoadOptions.DocDefault).Save("Out.pdf", SaveOptions.PdfDefault);
And also to Stephen, the following line will not give you the result which you are hoping to achieve:
string content = File.ReadAllText(file.ToString());
Note that DOCX files are actually a zipped group of files and folders and the "content" that you get from ReadAllText will not make any sence. Note that you can also use the above solution because it can process DOCX files in .NET as well.
Or you can read this article about finding a text in DOCX file.
Stephen RajPosted Dec 6, 2013, 2:52 AM
cs.aspx
YinPosted Oct 8, 2012, 9:20 PM
Sukesh MarlaPosted Oct 8, 2012, 4:28 PM
Secondly if you still want to convert, share the code then only we can help you.
Simplest idea for achieving the same is, Read the Doc File ,store the content into a string variable and finally create a text file wth the content.
I think StreamReader and StreamWriter might help you with the same.
Check this is correct answer if it helped.