我想将doc转换为html并浏览许多网站,我想出了这段代码,可以根据需要运行。
Protected Sub Upload(ByVal sender As Object, ByVal e As EventArgs)
Dim missingType As Object = Type.Missing
Dim readOnlyObject As Object = True
Dim isVisible As Object = False
Dim documentFormat As Object = 8
Dim randomName As String = DateTime.Now.Ticks.ToString
Dim htmlFilePath As Object = (Server.MapPath("~/Uploads/") _
& (randomName + ".htm"))
Dim directoryPath As String = (Server.MapPath("~/Uploads/") _
& (randomName + "_files"))
'Upload the word document and save to Temp folder
FileUpload1.SaveAs((Server.MapPath("~/Uploads/") + Path.GetFileName(FileUpload1.PostedFile.FileName)))
Dim fileName As Object = FileUpload1.PostedFile.FileName
Dim applicationclass As ApplicationClass = New ApplicationClass
applicationclass.Documents.Open(fileName)
applicationclass.Visible = False
Dim document As Document = applicationclass.ActiveDocument
'Save the word document as HTML file
document.SaveAs(htmlFilePath, documentFormat)
'Close the word document
document.Close()
'Delete the Uploaded Word File
File.Delete((Server.MapPath("~/Uploads/") + Path.GetFileName(FileUpload1.PostedFile.FileName)))
Dim bytes() As Byte
Dim fs As FileStream = New FileStream(htmlFilePath.ToString, FileMode.Open, FileAccess.Read)
Dim reader As BinaryReader = New BinaryReader(fs)
bytes = reader.ReadBytes(CType(fs.Length, Integer))
fs.Close()
Response.BinaryWrite(bytes)
Response.Flush()
System.IO.File.Delete(htmlFilePath.ToString)
Response.End()
End Sub
我在点击按钮
上调用此方法 <div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button runat="server" ID="btnUpload" Text="Upload" onClick="Upload" />
</div>
转换结果显示在同一屏幕上。我想让它在一个新窗口中打开。如果有人帮我这个,我会很高兴。