2011-01-25 74 views
0

我有一個問題,我幾個月來一直無法找到答案。我將word doc恢復爲varbinary(max)。我可以根據全文搜索檢索簡歷 - 沒問題。但是,簡歷以下面的代碼作爲.ashx文件中的word文檔檢索。我真的需要在網站上實現點擊突出顯示,以便用戶可以查看返回的簡歷是否合適。我不認爲這可以從.ashx文件中完成,所以我認爲我需要能夠在aspx頁面中將html作爲html打開,並且可能使用javascript來執行命中突出顯示,或者只返回文本內容word文檔以某種方式處理文本並在用html標籤顯示之前操作文本。我無法找到解決問題的任何地方。我真的希望有人能指引我走向正確的方向。如何打開varbinary word doc爲HTML

在此先感謝您的任何建議。

Imports System.io 
Imports System.Web 
Imports System.Data 
Imports System.Data.SqlClient 

  

Public Class ReadResume : Implements IHttpHandler 

Const conString As String = "Data Source=tcp:sql2k804.discountasp.net;Initial Catalog=SQL2008R2_284060_resumedata;User ID=SQL2008R2_284060_resumedata_user;Password=mypwd2314;" 

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest 

Dim con As SqlConnection = New SqlConnection(conString) 

Dim cmd As SqlCommand = New SqlCommand("Select ResumeDoc, DocTypeExtension From ResumeTable WHERE [email protected]", con) 

Dim CId As String = System.Web.HttpContext.Current.Request.QueryString("Para") 
cmd.Parameters.AddWithValue("@CandidateId", CId) 

Using con 
con.Open() 
Dim myReader As SqlDataReader = cmd.ExecuteReader 
If myReader.Read() Then 
    context.Response.Clear() 
    context.Response.ClearContent() 
    context.Response.ClearHeaders() 
    Dim file() As Byte = CType(myReader("ResumeDoc"), Byte()) 
    Dim doc_type As String = CType(myReader("DocTypeExtension"), String) 
    context.Response.ContentEncoding = System.Text.Encoding.UTF8 
    context.Response.ContentType = "Application/msword" 
    context.Response.AddHeader("content-disposition", "Candidate Resume") 
    context.Response.BinaryWrite(file) 
End If 

End Using 

End Sub 



Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable 

Get 

Return False 

End Get 

End Property 



End Class 

回答

0

您可以使用Microsoft Office COM組件處理Word文檔。例如,是到Word轉換爲HTML的方式:http://rongchaua.net/blog/c-convert-word-to-html/

UPDATE: 還有其他的解決方案。

如果只有.DOCX(不.DOC)文件,那麼你可以使用這個簡單的代碼來提取的docx文件明文:http://www.codeproject.com/KB/office/ExtractTextFromDOCXs.aspx這是相同的代碼:http://conceptdev.blogspot.com/2007/03/open-docx-using-c-to-extract-text-for.html

有閱讀一些商業庫/寫Word文檔: http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx http://www.cellbi.com/Products.aspx

+0

謝謝帕維爾,我檢查了鏈接。一旦文件處於Byte數組階段而不是將文件保存到E:/目錄,是否有任何方法可以實現這一點?即保持在內存中的一切 – Doug 2011-01-25 20:35:04