?
Solved

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

Posted on 2008-10-22
8
Medium Priority
?
676 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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
 
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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

770 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