File Upload Office 2007 documents, file corrupt/cant open

Discussion in 'ASP General' started by B, Sep 7, 2007.

  1. B

    B Guest

    I have a process that uploads files and has been working for well over a year
    or more. It uploads all file types and works fine.

    The customer now wants to upload Office 2007 documents (.docx, etc) and it
    appears the files uploaded correctly but when I go to open them I get the
    following error: "There was an error opening the file".

    I do not have office 2007 but I do have the conversion/compatibility package
    that allows me to open office 2007 documents. I can open the document just
    fine, then upload it, and click the link on the web page that opened it (or
    go directly to the folder where it was uploaded to) and try to open it and I
    get the above error.

    I can not find anything when searching for this issue except some
    notes/mentions that these files are treated as .zip files sometimes?? But
    have no clue what that means to my problem.

    I am using standard ASP code to upload the documents using IIS. If you need
    an example of the code let me know (it is a big function). So if you need
    the code let me know.

    If anyone can help I would appreciate it.

    Thank You.
     
    B, Sep 7, 2007
    #1
    1. Advertising

  2. "B" <> wrote in message
    news:...
    > I have a process that uploads files and has been working for well over a

    year
    > or more. It uploads all file types and works fine.
    >
    > The customer now wants to upload Office 2007 documents (.docx, etc) and it
    > appears the files uploaded correctly but when I go to open them I get the
    > following error: "There was an error opening the file".
    >
    > I do not have office 2007 but I do have the conversion/compatibility

    package
    > that allows me to open office 2007 documents. I can open the document

    just
    > fine, then upload it, and click the link on the web page that opened it

    (or
    > go directly to the folder where it was uploaded to) and try to open it and

    I
    > get the above error.
    >
    > I can not find anything when searching for this issue except some
    > notes/mentions that these files are treated as .zip files sometimes?? But
    > have no clue what that means to my problem.
    >
    > I am using standard ASP code to upload the documents using IIS. If you

    need
    > an example of the code let me know (it is a big function). So if you need
    > the code let me know.
    >
    > If anyone can help I would appreciate it.
    >


    You need to add the office 2007 document types to your IIS server's mime
    map. You can find the list of mime types here:-

    http://technet2.microsoft.com/Offic...c9a4-413c-a1d3-40c97e340c5a1041.mspx?mfr=true

    (Why MS haven't placed this list in some more accessable place I can't
    imagine).


    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Sep 7, 2007
    #2
    1. Advertising

  3. B

    B Guest

    Anthony,

    It looks like that is the problem. I had my server admin check our web
    server and they are not registred mime types.

    I requsted they updated the mime types with the link you sent. Hopefully
    this will fix the problem and I will let you know when they update the mime
    types if this fixed it.

    Thanks for the help!!!! I was searching online for about an hour and could
    not find anything even close to this.
     
    B, Sep 7, 2007
    #3
  4. B

    B Guest

    Anthony,

    Well this worked for one of my sites that uploads documents one way but it
    still does not work when uploading files a different way.

    The way I am doing it is on this page:
    http://www.stardeveloper.com/articles/display.html?article=2001042501&page=2

    I know it is a lot of code but maybe you can see a quick problem with it?
    Or anyone else?



    "B" wrote:

    >
    > Anthony,
    >
    > It looks like that is the problem. I had my server admin check our web
    > server and they are not registred mime types.
    >
    > I requsted they updated the mime types with the link you sent. Hopefully
    > this will fix the problem and I will let you know when they update the mime
    > types if this fixed it.
    >
    > Thanks for the help!!!! I was searching online for about an hour and could
    > not find anything even close to this.
    >
    >
     
    B, Sep 10, 2007
    #4
  5. B

    B Guest

    I think the main section of code that is doing the actual upload is below.
    Could something in here for the office 2007 files be causing a problem?


    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)
    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
     
    B, Sep 10, 2007
    #5
  6. "B" wrote:
    > Well this worked for one of my sites that uploads documents one way but
    > it still does not work when uploading files a different way.
    >
    > The way I am doing it is on this page:
    > http://www.stardeveloper.com/articles/display.html?article=2001042501&page=2
    >
    > I know it is a lot of code but maybe you can see a quick problem with it?
    > Or anyone else?


    Have you registered the .docx extension with IIS? This is required in IIS6.

    Use the IIS Manager to view the web site properties. On the [HTTP Headers]
    tab, click the [Mime Types...] button. If .docx is not listed, add it, with
    MIME type "application/msword".



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Sep 12, 2007
    #6
  7. Dave Anderson" <> wrote in message
    news:e5XhJ%...
    > "B" wrote:
    > > Well this worked for one of my sites that uploads documents one way but
    > > it still does not work when uploading files a different way.
    > >
    > > The way I am doing it is on this page:
    > >

    http://www.stardeveloper.com/articles/display.html?article=2001042501&page=2
    > >
    > > I know it is a lot of code but maybe you can see a quick problem with

    it?
    > > Or anyone else?

    >
    > Have you registered the .docx extension with IIS? This is required in

    IIS6.
    >
    > Use the IIS Manager to view the web site properties. On the [HTTP Headers]
    > tab, click the [Mime Types...] button. If .docx is not listed, add it,

    with
    > MIME type "application/msword".
    >
    >



    application/vnd.openxmlformats-officedocument.wordprocessingml.document


    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Sep 13, 2007
    #7
  8. "Anthony Jones" wrote:
    >> If .docx is not listed, add it, with MIME type "application/msword".

    >
    > application/vnd.openxmlformats-officedocument.wordprocessingml.document


    Or that.

    It's funny, I just used the Word 8 value as an example because I don't have
    Office 2007 installed. Imagine how shocked I was to find the entry
    [HKEY_CLASSES_ROOT\.docx\Content Type] on my box. Had I known it was there,
    I would have made the same recommendation.


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Sep 13, 2007
    #8
  9. B

    B Guest

    Well this should not be a problem anymore as the Mime types were updated and
    it is working if I use a different file upload method. It is just not
    working with this specific method/function.
     
    B, Sep 17, 2007
    #9
  10. B

    B Guest

    Well I found the problem. The mime type fixed it for the one script as I
    said, but the other script (I linked to above) it did not.

    The problem was in the code at the bottom. The code was looping through 1
    to lengh of binary data. I checked and it was always adding a bite to the
    file size. It did not cause problems with any of the other file types but
    the 2007 files it did apparently. If I changed it to go to -1 length it
    works now (and the file size is exactly the same).

    So found and fixed it.

    Thanks for all your help.



    'For tPoint = 1 to LenB(temp)
    For tPoint = 1 to LenB(temp)-1
    file.Write Chr(AscB(MidB(temp,tPoint,1)))
    Next
     
    B, Sep 17, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stan Accrington
    Replies:
    1
    Views:
    970
    Michael Borgwardt
    May 13, 2004
  2. Nagaraj
    Replies:
    1
    Views:
    900
    Lionel B
    Mar 1, 2007
  3. =?Utf-8?B?VA==?=

    Office 2007 documents not appearing in iframe

    =?Utf-8?B?VA==?=, Mar 6, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    436
    Patrice
    Mar 6, 2007
  4. John Kotuby
    Replies:
    9
    Views:
    317
    Mark Rae
    May 17, 2007
  5. apondu
    Replies:
    1
    Views:
    337
    Alvin Bruney [MVP]
    May 31, 2007
Loading...

Share This Page