Solved

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

Posted on 2008-10-22
8
665 Views
Last Modified: 2012-05-05
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
Comment
Question by:Eric_Trogdon
  • 4
  • 3
8 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22781936
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
 
LVL 8

Expert Comment

by:LocoTechCJ
ID: 22781961
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
 

Author Comment

by:Eric_Trogdon
ID: 22787266
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
 
LVL 8

Expert Comment

by:LocoTechCJ
ID: 22788454
Try changing line 59
  For tPoint = 1 to LenB(temp)
To
  For tPoint = 1 to LenB(temp)-1

--LTCJ

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 8

Expert Comment

by:LocoTechCJ
ID: 22788600
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
 

Author Comment

by:Eric_Trogdon
ID: 22788619
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
 

Author Comment

by:Eric_Trogdon
ID: 22788660
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
 

Accepted Solution

by:
Eric_Trogdon earned 0 total points
ID: 22831867
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now