1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Private Sub exportbtt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exportbtt.Click
'Response.Redirect("default.aspx")
'this function request the current page and saves it to a file in html format.
'Then it redirect the user to another page where it export the html file to MS Word.
'Then the user is redirected back to the current page and the file is deleted
Dim URL As String = "http://ideaworks/submissiondetails.aspx?id=" & submission.submissionId & "&do=export"
Dim arequest As WebRequest = WebRequest.Create(URL)
Dim aresponse As WebResponse = arequest.GetResponse()
Dim reader As StreamReader = New StreamReader(aresponse.GetResponseStream())
Dim str As String = reader.ReadLine()
'Preparing to make a Word document
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=Submission.doc")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.word"
'Tools to write in MS Word
Dim monStringWriter As StringWriter = New System.IO.StringWriter()
Dim monHtmlTextWriter As HtmlTextWriter = New HtmlTextWriter(monStringWriter)
'While there is still html code to write, read and write the next line
While Not str.Equals("</HTML>")
monHtmlTextWriter.Write(str)
str = reader.ReadLine()
End While
'closing file
reader.Close()
'Write everything in MS Word then close the word document
Response.Write(monStringWriter.ToString())
Response.End()
End Sub |
Partager