Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi guys

I have made an application that stores word files, and PDF IN SQL SERVER.
It stores Doc and Docx files successfully. The problem is that it can nοt open Docx files.
Doc files open successfully.

Please help

Thanks in advance

Here is the code :
VB
Private Sub Viewdoc(ByVal Idx As Integer)
       Kill_proses()
       System.Threading.Thread.Sleep(500)
       Dim objNewFileStream As FileStream = Nothing
       If My.Computer.FileSystem.DirectoryExists(temp) = True Then
           My.Computer.FileSystem.DeleteDirectory(temp, FileIO.DeleteDirectoryOption.DeleteAllContents)
       End If
       My.Computer.FileSystem.CreateDirectory(temp)
       Try
           Dim isigroup As DataTable
           objdata = New GlobalClass
           isigroup = objdata.QueryDatabase("select * from docu where id=" & id_docx)
           If isigroup.Rows.Count = 1 Then
               Dim nama_file As String = isigroup.Rows(0).Item(4).ToString
               isigroup = objdata.QueryDatabase("Select * from docs where docu_id =" & id_docx)
               Dim bytes() As Byte
               Dim imgStream As MemoryStream
               id_img = isigroup.Rows(0).Item(0)
               bytes = CType(isigroup.Rows(0).Item(2), Byte())
               imgStream = New MemoryStream(bytes)
               imgStream.Position = 0
               objNewFileStream = New FileStream(temp & "/" & nama_file, FileMode.OpenOrCreate, FileAccess.Write)
               Dim objBuffer(256) As Byte
               Dim intBytesRead As Integer = imgStream.Read(objBuffer, 0, 256)
               While intBytesRead > 0
                   objNewFileStream.Write(objBuffer, 0, intBytesRead)
                   intBytesRead = imgStream.Read(objBuffer, 0, 256)
               End While
               If Not imgStream Is Nothing Then
                   imgStream.Close()
               End If
               If Not objNewFileStream Is Nothing Then objNewFileStream.Close()
               wb.Focus()
               wb.Navigate(New Uri(temp & "\" & nama_file))
                 End If
       Catch ex As Exception
           MsgBox(ex.ToString)
       End Try
   End Sub
Posted
Updated 29-Dec-13 5:33am
v2
Comments
Sergey Alexandrovich Kryukov 29-Dec-13 12:30pm    
What are your trying to do with this code? How can it be related with opening of a DOCX file? If you are trying to open some file, why are you creating a directory (there are no files in a new directory :-)..?
—SA
jomachi 29-Dec-13 12:36pm    
I have a Temp file in Debug directory who stores only the last document.

If you only want to work with some existing office documents, you can use Open XML SDK:
http://www.microsoft.com/en-us/download/details.aspx?id=30425[^].

This way, you can support new XML-based Office formats (such as .DOCX, .XLSX), ECMA-376 standard:
http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats[^],
http://en.wikipedia.org/wiki/Office_Open_XML[^].

This way, you can work without Office installed. Also, the documents are supported by 3rd-party software. Please see my past answers:
Convert Office-Documents to PDF without interop[^],
Need a rather unique WPF text editor control[^],
Hi how can i display word file in windows application using c#.net[^],
Read a word file without using Interop.word dll...Do not want to install word in IIS..[^].

This is another option: http://npoi.codeplex.com/[^].

Using Office Interop in the server's environment is not recommended even by Microsoft, please see:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].

—SA
 
Share this answer
 
What Microsoft Word version are you using?

You at least need Word 2003 with a support pack for DOCX files.

See this link --> http://office.microsoft.com/en-us/word-help/open-a-word-2007-document-in-an-earlier-version-of-word-HA010044473.aspx[^]
 
Share this answer
 
v2
Comments
jomachi 29-Dec-13 11:30am    
I use Office 2010 my friend see the code. I edit the question
Sergey Alexandrovich Kryukov 29-Dec-13 12:33pm    
This is not an answer; this advice is totally unrelated to the problem of using the DOCX documents programmatically.
—SA
Kees van Spelde 29-Dec-13 12:47pm    
Hi,

When I answered this question there was no code example present. That is why I pointed him to a possible solution with the Word 2003 extension pack

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900