Hi everyone,

I have an interesting situation at hand.
I already succeeded in uploading files (.doc, .docx, etc) to both the database and a folder on the server. I can also download the files to client systems successfully without any issue.

However, my manager wants people to be able to see the content of some of the file on the home page of our website. I've been thinking on how to extract the content of the files (stored in database and server) and then display it on the page.

He says the files can be updated from time to time, thus the display should be the most recent update. This is why I've been thinking of extracting the content of the data already uploaded.

Any ideas.

Thanks sufyan but I do not intend to "open" the document, I only want to extract the text in the document.

Yes, extract the text. That's all

Yeah right, document open means in memory not document viewer. Hopefully in above link you can see in detail.

Thanks sufyan,

I eventually worked around your solution with like this

Imports Microsoft.Office.Interop  'Requires reference to Office.dll 

Partial Class _Default
    Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim objWord As Word.ApplicationClass
    Dim strText As String
    objWord = New Word.Application()
    With objWord
      .Visible = False
      .Documents.Open(FileLocation_FileName, , True)
      .WordBasic.EditSelectAll()
      .WordBasic.SetDocumentVar("MyVar", .ActiveDocument.ActiveWindow.Selection.Text)
      strText = .WordBasic.GetDocumentVar("MyVar")
      Label1.Text = InsertNewLineChars(Strings.Left(strText, Len(strText) - 1))
      .Documents.Close(0)
      .Quit()
    End With
    'End Sub

  End Sub

  Private Function InsertNewLineChars(ByVal strText As String) As String
    Dim pos As Integer, l As Integer
    pos = 1
    Do While pos < Len(strText)
      l = Strings.InStr(pos, strText, vbCr)
      If l = 0 Then Exit Do
      strText = Strings.Left(strText, l - 1) & vbCrLf & Mid(strText, l + 1)
      pos = l + 2
    Loop
    Return strText
  End Function
End Class

Thats great, please mark it solve if it really helped you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.