c# - Conversion of word file to HTML and after some edit in HTML convert it back to docx -
i working on utility users come , upload word document application , assign specific persons, after assignment specific users come application , suggest changes formatting own , save it. , can download updated file reference.
what doing achieving - step 1- while user uploading word file (docx/doc), code converting html file using below code -
object filename; object missingtype = type.missing; object readonly = false; object isvisible = false; object documentformat = 8; //original file location application uploaded document future reference filename = configurationmanager.appsettings["wordfilepath"].tostring() + item.guid + item.documentextention; //html file location application save file html object htmldirectorypath = configurationmanager.appsettings["htmlfilepath"].tostring() + item.guid + ".htm"; //conversion process 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; document.saveas(ref htmldirectorypath, ref documentformat, 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); document.close(ref missingtype, ref missingtype, ref missingtype);
note: - above code do, convert doc file html , saving specified location file supported files folder. just this
step 2: user update text , doing using rangy highligher. user can update text, highlight text html file , save back.[this working fine]
step 3: comes difficult thing, anytime user can come , may download latest file server. job convert html word file , promt download alert. have tried using above code says that, applicationclass unable open specified file , when tried read , write new file using bytearray, downloaded file says "unable open, data corrupt"
note: simple word files converting , html when comes complex word document having images , other things in above error start raise.
string filepathhtml = system.configuration.configurationmanager.appsettings["htmlfilepath"] + objdocument.guid + ".htm"; //object filehtmlpathtemp = system.configuration.configurationmanager.appsettings["htmlfilepath"] + "temp\\" + objdocument.guid + ".htm"; string filepathtemp = system.configuration.configurationmanager.appsettings["htmlfilepath"] + "temp\\" + guid + ".doc"; streamreader objreader; objreader = new streamreader(filepathhtml); string content = objreader.readtoend(); var path = system.configuration.configurationmanager.appsettings["livepathwithcontent"] + "documents/html/" + objdocument.guid + "_files"; content = content.replace(objdocument.guid + "_files", system.configuration.configurationmanager.appsettings["livepathwithcontent"] + "documents/html/" + objdocument.guid + "_files"); streamwriter objwriter = new streamwriter(filepathtemp); objwriter.write(content); objwriter.close(); string contenttype = ""; if (objdocument.documentextention.tolower().replace(".docx",".doc") == ".doc") { contenttype = "application/msword;charset=utf-8"; } else { contenttype = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; } //byte[] arrbytes = filetobytearray(filepathhtml.tostring()); //system.io.file.writeallbytes(filepathtemp.tostring(), arrbytes); // requires system.io return file(filepathtemp.tostring(), contenttype, objdocument.documentname.replace(".docx", ".doc"));
please find sample doc files on cloud server https://drive.google.com/folderview?id=0b_wgzdvwphqcaehmmwpmnxfmt1u&usp=sharing
Comments
Post a Comment