• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 679
  • Last Modified:

Can't upload Office 2007 docx to existing ASP web page

I have a classic ASP page that has been working fine for several years. the customer now is using Office 2007 and needs to upload files. the .doc xls extensions work just fine but the Office 2007 extensions with .docX are not working.

any info or links on this?
0
Eric_Trogdon
Asked:
Eric_Trogdon
  • 4
  • 3
1 Solution
 
hieloCommented:
most likely your processing script is accepting only files with specific extensions. The browser will not impose those restrictions on the user. You need to look at your processing script. Post your code if you can't solve this.
0
 
LocoTechCJCommented:
Is it that the site limits files to 3-letter extensions?  It may do this unintentionally by looking at uploaded files in a "*.???" format.  Does it give a specific error?  Are you the developer of the file or have any code to look at?   There could be numerous things that could cause the problem.

--LTCJ
0
 
Eric_TrogdonAuthor Commented:
I'm not the developer of this section of the application but I am the guy that was given the task to maintain this legacy app. My strenght in more .NET and C# but I remember doing som Classic ASP while in college but I'm far from a guru in it.

 I've stepped through the code and have not found a snipit that defines accepted scripts. I have developed a .NET  attachment page that does limit what the use can uplaod and figured that is how this function would work also, but it does not.

I've set several break points and end up on a page named loader.asp Below in the code.  When I step through the code and I get to getContentType when attaching a non 2007 MsWord doc and hover over the dict(name) it reads application/msword. When I try to attach a MsWord 2007 doct it reads appliaction/(then it has a long string of stuff that is truncated where I can't read it).

From my research it seems there is a Scripting Dictionary I need to update but haven't found a good resource explaining how.
 Class Loader
    Private dict
    
    Private Sub Class_Initialize
      Set dict = Server.CreateObject("Scripting.Dictionary")
    End Sub
 
    Private Sub Class_Terminate
      If IsObject(intDict) Then
        intDict.RemoveAll
        Set intDict = Nothing
      End If
      If IsObject(dict) Then
        dict.RemoveAll
        Set dict = Nothing
      End If
    End Sub
 
    Public Property Get Count
      Count = dict.Count
    End Property
 
    Public Sub Initialize
      If Request.TotalBytes > 0 Then
        Dim binData
          binData = Request.BinaryRead(Request.TotalBytes)
          getData binData
      End If
    End Sub
 
    Public Function getFileData(name)
      If dict.Exists(name) Then
        getFileData = dict(name).Item("Value")
        Else
        getFileData = ""
      End If
    End Function
 
    Public Function getValue(name)
      Dim gv
      If dict.Exists(name) Then
        gv = CStr(dict(name).Item("Value"))
        
        gv = Left(gv,Len(gv)-2)
        getValue = gv
      Else
        getValue = ""
      End If
    End Function
 
    Public Function saveToFile(name, path)
      If dict.Exists(name) Then
        Dim temp
          temp = dict(name).Item("Value")
        Dim fso
          Set fso = Server.CreateObject("Scripting.FileSystemObject")
        Dim file
          Set file = fso.CreateTextFile(path)
            For tPoint = 1 to LenB(temp)
                file.Write Chr(AscB(MidB(temp,tPoint,1)))
            Next
            file.Close
          saveToFile = True
      Else
          saveToFile = False
      End If
    End Function
 
    Public Function getFileName(name)
      If dict.Exists(name) Then
        Dim temp, tempPos
          temp = dict(name).Item("FileName")
          tempPos = 1 + InStrRev(temp, "\")
          getFileName = Mid(temp, tempPos)
      Else
        getFileName = ""
      End If
    End Function

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LocoTechCJCommented:
Try changing line 59
  For tPoint = 1 to LenB(temp)
To
  For tPoint = 1 to LenB(temp)-1

--LTCJ

0
 
LocoTechCJCommented:
Something you may want to check is if you have registered the .docx extension in IIS.  Check this out:

http://www.bram.us/2007/05/25/office-2007-mime-types-for-iis/
http://wdg.uncc.edu/Microsoft_Office_2007_MIME_Types_for_Apache_and_IIS

Try this before the code change.  It may be all you need.

--LTCJ
0
 
Eric_TrogdonAuthor Commented:
Same error

The JIT error reads:
unhandled exception('Multiple-dtep OLE DB operation generated errors. Ched each OLD DB status value, if avaliable. No work was done.') occurred in inetinfo.exe[816]

When I hover over rs("ContentType") = contentType
during debugging it reads:
contentType ="application/vnd.openxmlformats-officedocument.wordprocessingml.document"

I read  somewhere I needed to register this with my ISS. I tried this and still have the error.
0
 
Eric_TrogdonAuthor Commented:
here is a more complete copy of the code

Class Loader
    Private dict
    
    Private Sub Class_Initialize
      Set dict = Server.CreateObject("Scripting.Dictionary")
    End Sub
 
    Private Sub Class_Terminate
      If IsObject(intDict) Then
        intDict.RemoveAll
        Set intDict = Nothing
      End If
      If IsObject(dict) Then
        dict.RemoveAll
        Set dict = Nothing
      End If
    End Sub
 
    Public Property Get Count
      Count = dict.Count
    End Property
 
    Public Sub Initialize
      If Request.TotalBytes > 0 Then
        Dim binData
          binData = Request.BinaryRead(Request.TotalBytes)
          getData binData
      End If
    End Sub
 
    Public Function getFileData(name)
      If dict.Exists(name) Then
        getFileData = dict(name).Item("Value")
        Else
        getFileData = ""
      End If
    End Function
 
    Public Function getValue(name)
      Dim gv
      If dict.Exists(name) Then
        gv = CStr(dict(name).Item("Value"))
        
        gv = Left(gv,Len(gv)-2)
        getValue = gv
      Else
        getValue = ""
      End If
    End Function
 
    Public Function saveToFile(name, path)
      If dict.Exists(name) Then
        Dim temp
          temp = dict(name).Item("Value")
        Dim fso
          Set fso = Server.CreateObject("Scripting.FileSystemObject")
        Dim file
          Set file = fso.CreateTextFile(path)
            For tPoint = 1 to LenB(temp)
                file.Write Chr(AscB(MidB(temp,tPoint,1)))
            Next
            file.Close
          saveToFile = True
      Else
          saveToFile = False
      End If
    End Function
 
    Public Function getFileName(name)
      If dict.Exists(name) Then
        Dim temp, tempPos
          temp = dict(name).Item("FileName")
          tempPos = 1 + InStrRev(temp, "\")
          getFileName = Mid(temp, tempPos)
      Else
        getFileName = ""
      End If
    End Function
 
    Public Function getFilePath(name)
      If dict.Exists(name) Then
        Dim temp, tempPos
          temp = dict(name).Item("FileName")
          tempPos = InStrRev(temp, "\")
          getFilePath = Mid(temp, 1, tempPos)
      Else
        getFilePath = ""
      End If
    End Function
 
    Public Function getFilePathComplete(name)
      If dict.Exists(name) Then
        getFilePathComplete = dict(name).Item("FileName")
      Else
        getFilePathComplete = ""
      End If
    End Function
 
    Public Function getFileSize(name)
      If dict.Exists(name) Then
        getFileSize = LenB(dict(name).Item("Value"))
      Else
        getFileSize = 0
      End If
    End Function
 
    Public Function getFileSizeTranslated(name)
      If dict.Exists(name) Then
        temp = LenB(dict(name).Item("Value"))
          If temp <= 1024 Then
            getFileSizeTranslated = temp & " bytes"  
          Else
            temp = FormatNumber((temp / 1024), 2)
            getFileSizeTranslated = temp & " kilobytes"
          End If
      Else
        getFileSizeTranslated = ""
      End If
    End Function
 
    Public Function getContentType(name)
      If dict.Exists(name) Then
        getContentType = dict(name).Item("ContentType")
      Else
        getContentType = ""
      End If
    End Function
 
  Private Sub getData(rawData)
    Dim separator 
      separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)
 
    Dim lenSeparator
      lenSeparator = LenB(separator)
 
    Dim currentPos
      currentPos = 1
    Dim inStrByte
      inStrByte = 1
    Dim value, mValue
    Dim tempValue
      tempValue = ""
 
    While inStrByte > 0
      inStrByte = InStrB(currentPos, rawData, separator)
      mValue = inStrByte - currentPos
 
      If mValue > 1 Then
        value = MidB(rawData, currentPos, mValue)
 
        Dim begPos, endPos, midValue, nValue
        Dim intDict
          Set intDict = Server.CreateObject("Scripting.Dictionary")
 
          begPos = 1 + InStrB(1, value, ChrB(34))
          endPos = InStrB(begPos + 1, value, ChrB(34))
          nValue = endPos
 
        Dim nameN
          nameN = MidB(value, begPos, endPos - begPos)
 
        Dim nameValue, isValid
          isValid = True
          
          If InStrB(1, value, stringToByte("Content-Type")) > 1 Then
 
            begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
            endPos = InStrB(begPos + 1, value, ChrB(34))
 
            If endPos = 0 Then
              endPos = begPos + 1
              isValid = False
            End If
 
            midValue = MidB(value, begPos, endPos - begPos)
              intDict.Add "FileName", trim(byteToString(midValue))
 
          begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
          endPos = InStrB(begPos, value, ChrB(13))
 
            midValue = MidB(value, begPos, endPos - begPos)
              intDict.Add "ContentType", trim(byteToString(midValue))
 
            begPos = endPos + 4
            endPos = LenB(value)
 
            nameValue = MidB(value, begPos, ((endPos - begPos) - 1))
          Else
            nameValue = trim(byteToString(MidB(value, nValue + 5)))
          End If
 
          If isValid = True Then
 
            intDict.Add "Value", nameValue
            intDict.Add "Name", nameN
 
            dict.Add byteToString(nameN), intDict
          End If
      End If
 
      currentPos = lenSeparator + inStrByte
    Wend
  End Sub
  
  End Class
 
  Private Function stringToByte(toConv)
    Dim tempChar
     For i = 1 to Len(toConv)
       tempChar = Mid(toConv, i, 1)
      stringToByte = stringToByte & chrB(AscB(tempChar))
     Next
  End Function
 
  Private Function byteToString(toConv)
    For i = 1 to LenB(toConv)
      byteToString = byteToString & Chr(AscB(MidB(toConv,i,1))) 
    Next
  End Function

Open in new window

0
 
Eric_TrogdonAuthor Commented:
Turns out the filed in the data base that held the value for content type was set to 20. I increased the value and this solved my problem.  Doh!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now