File Upload Office 2007 documents, file corrupt/cant open

File Upload Office 2007 documents, file corrupt/cant open

am 07.09.2007 19:44:01 von 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.

Re: File Upload Office 2007 documents, file corrupt/cant open

am 07.09.2007 20:39:22 von Anthony Jones

"B" wrote in message
news:E189D807-F764-4839-A937-AE6AE39C0A03@microsoft.com...
> 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/Office/ja-JP/library/f88d06fb- 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

Re: File Upload Office 2007 documents, file corrupt/cant open

am 07.09.2007 21:58:07 von 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.

Re: File Upload Office 2007 documents, file corrupt/cant open

am 10.09.2007 16:24:07 von B

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=2 001042501&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.
>
>

Re: File Upload Office 2007 documents, file corrupt/cant open

am 10.09.2007 20:10:02 von 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

Re: File Upload Office 2007 documents, file corrupt/cant open

am 12.09.2007 17:13:53 von Dave Anderson

"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=2 001042501&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.

Re: File Upload Office 2007 documents, file corrupt/cant open

am 13.09.2007 10:12:04 von Anthony Jones

Dave Anderson" wrote in message
news:e5XhJ%23U9HHA.980@TK2MSFTNGP06.phx.gbl...
> "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=2 001042501&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.wordprocessing ml.document


--
Anthony Jones - MVP ASP/ASP.NET

Re: File Upload Office 2007 documents, file corrupt/cant open

am 13.09.2007 15:43:09 von Dave Anderson

"Anthony Jones" wrote:
>> If .docx is not listed, add it, with MIME type "application/msword".
>
> application/vnd.openxmlformats-officedocument.wordprocessing ml.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.

Re: File Upload Office 2007 documents, file corrupt/cant open

am 17.09.2007 15:34:04 von 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.

Re: File Upload Office 2007 documents, file corrupt/cant open

am 17.09.2007 16:48:02 von 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