asp.net VB use htm to word , but when the download file is opening ,it got error
Clash Royale CLAN TAG#URR8PPP
asp.net VB use htm to word , but when the download file is opening ,it got error
I used Word 365 to convert a WORD file into an HTM template for ASP.net Vb.
And the program will use this template when it is executed, and replace the text inside, and produce a new WORD file.
However, when this downloaded file is opened with 365, it will get an error.
"The file is corrupted and cannot be opened."
Can anyone help me fix this problem?
Here is my program
Dim htmlWrite As New StringBuilder
Dim dv1 As DataView = db_CE04.getdv_by_fk_ce01_aid(aid)
If dv1.Count > 0 Then
For i As Integer = 0 To dv1.Count - 1
htmlWrite.Append(IO.File.ReadAllText(Server.MapPath("~/html/In_service_or_leave/onbord_report.htm")))
htmlWrite.Replace("[internal_id]", title)
htmlWrite.Replace("[year]", year(now()))
htmlWrite.Replace("[form_text]", form_text)
htmlWrite.Replace("[form_no]", form_no)
htmlWrite.Replace("[employee_name]", employee_name")
htmlWrite.Replace("[law_id]", law_id)
htmlWrite.Replace("[sex]", gender)
htmlWrite.Replace("[unit_name]", unit_id)
htmlWrite.Replace("[position_name]", position_name)
htmlWrite.Replace("[position_level]", position_level_name & salary_level_name)
htmlWrite.Replace("[reason]", reason)
Next
End If
Dim word_name As String = "test"& "_XXXX(" & Now.ToString("yyyyMMddHHmmss") & ").docx"
Response.ClearHeaders()
Response.Clear()
Response.Expires = 0
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=" & Server.UrlEncode(word_name))
Response.Charset = "UTF-8"
Response.ContentType = "application/ms-word"
Response.Write(htmlWrite.ToString)
Response.End()
Hint: if you save your Word document as a .docx file, you can open it with something like 7-zip and explore the contents. If you look in the "word" directory you will find a file "document.xml". If you edit that file and put it back into the zip archive then you can open it in Word and see the changes.
– Andrew Morton
Aug 12 at 16:48
thank you @AndrewMorton , I found the problem
– Allen Lan
Aug 13 at 1:04
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You cannot put a ".docx" extension on an HTML file and then directly open it in Word. There is software available to manipulate Word documents on a server. Please note that Word itself is not suitable for the task.
– Andrew Morton
Aug 12 at 16:37