Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
developer
active.documents
automation
binary.file_format
clipboard.dde
com.add_ins
hosting.controls
internet_other
office.sdks
officedev
officedev.other
outlook.forms
outlook.vba
smarttags
vba
web.components
  
 
date: Mon, 7 Jul 2008 06:41:02 -0700,    group: microsoft.public.office.developer.officedev.other        back       


docx file corrupted when saved to database   
I have an application that saves word files to a SQL2005 database and 
retrieves them on demand.  It works fine for files saved in the doc format, 
but if the file is saved from the docx format, I cannot open it in my code.  
When I open the file retrieved from the database manually in word 2007, I get 
an error message "The file is corrupted and cannot be open".  then I get a 
second dialog box "some of the content cannot be read, if you trust the souce 
word will attempt to open it"  and then it does.
I have similar code which automates word and has it save the file to the 
database.  If I save the file in the old format I have no problems with it.  
If I save the file in the docx format, than I cannot reoppen it.


Here is the code for retrieving the document:
Dim myrow As bardpagesDS.SelTempPropFilesRow = 
myfileds.SelTempPropFiles.Rows(0)
        Dim mybuffer() As Byte
        Dim myext As String

        Select Case filetype
            Case "abstract"

                mybuffer = myrow.AbstractFile
                myext = myrow.ABSFiletype
            Case "body"
                mybuffer = myrow.ProposalFile
                myext = myrow.PropFileType

        End Select
        If My.Computer.FileSystem.FileExists(filetype + "." + myext) Then
            My.Computer.FileSystem.DeleteFile(filetype + "." + myext)
        End If
        Dim myfile As New IO.FileStream(filetype + "." + myext, 
IO.FileMode.Create, IO.FileAccess.ReadWrite)
        myfile.Write(mybuffer, 0, mybuffer.Length)
        myfile.Close()
        Return filetype + "." + myext

Code Which Uploads file
Public Function uploadfile(ByVal mytcn As Integer, ByVal mypw As String, 
ByVal myfile As HttpPostedFile, ByVal filetype As String) As String
            Try

                Dim myarray(myfile.ContentLength) As Byte
               
                Dim mybr As New System.IO.BinaryReader(myfile.InputStream)

                mybr.Read(myarray, 0, myfile.ContentLength)
                mybr.Close()
                Dim c As String = System.IO.Path.GetFileName(myfile.FileName)
                c = Right(c, 3)
                Dim myscmd As Data.SqlClient.SqlCommand
  
                       myscmd = Me.SCMD_AddAbstractFile
             
                With myscmd
                    .Parameters(1).Value = mytcn
                    .Parameters(2).Value = mypw
                    .Parameters(3).Value = c
                    .Parameters(4).Value = myarray
                  
                        .Connection.Open()
        
                    .ExecuteNonQuery()

                                    .Connection.Close()
                    End With
                Return "OK"
            Catch ex As Exception
                Return ex.Message
            End Try

        End Function
-- 
Haim Katz
BARD
date: Mon, 7 Jul 2008 06:41:02 -0700   author:   Haim am

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us