Wednesday, 15 May 2013

c# - I want to convert Microsoft Word document to .txt format and save it in my solution folder -



c# - I want to convert Microsoft Word document to .txt format and save it in my solution folder -

i using file uploader command , need convert uploaded .docx file .txt file used of code below:

object missingtype = type.missing; object readonly = true; object isvisible = false; object format = wdsaveformat.wdformattext; string randomname = datetime.now.ticks.tostring(); fileupload1.saveas(server.mappath("~/textdoc/") + path.getfilename(fileupload1.postedfile.filename)); object filename = fileupload1.postedfile.filename; object txtfilepath = server.mappath("~/textdoc/") + randomname + ".txt"; //open word document in background applicationclass applicationclass = new applicationclass(); applicationclass.documents.open(ref filename, ref readonly, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref isvisible, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype); applicationclass.visible = false; document document = applicationclass.activedocument; //save word document txt file document.saveas(ref txtfilepath, ref format, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype, ref missingtype); //close word document document.close(ref missingtype, ref missingtype, ref missingtype);

and changed 'filename' variable to

object filename = "~/" + path.getfullpath(fileupload1.filename);

then getting exception like:

this command not available because no document open.

please 1 help me..

you can utilize docx read/manipulate word documents no dependencies on office or interop.

find docx here

the project owner, cathal coffey posts on various docx topics here

i did quick , dirty "get started" type article on using docx here

it should relatively simple utilize docx pull text our of word doc , save plain .txt file.

i don't post links in answer. in case, however, since pointing alternative tool job done, seems appropriate.

c# asp.net ms-word office-interop

No comments:

Post a Comment