File Upload Office 2007 documents, file corrupt/cant open

B

B

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

Anthony Jones

B said:
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).
 
B

B

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

B

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
 
D

Dave Anderson

B said:
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".
 
A

Anthony Jones

Dave Anderson said:
B said:
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
 
D

Dave Anderson

Anthony Jones said:
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.
 
B

B

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

B

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top