RE: docx file corrupted when saved and retrieved from SQL2005



Good morning Haim. Welcome to Microsoft Newsgroup Support Service! My name
is Jialiang Ge [MSFT]. It's my pleasure to work with your on this issue.

I have reproduced the symptom "The file is corrupted and cannot be open"
for docx with your code. After debugging the program and looking into the
binary of the resulting docx, I find that the symptom is caused by the
declaration of buffer: Dim myarray(myfile.ContentLength) As Byte

Let's first look at the resolution of the issue, then I will explain "WHY".
Last, I will share the skills to trouble-shoot this kind of issues, which
may benefit you in future.

--- RESOLUTION ---
Change the code line

Dim myarray(myfile.ContentLength) As Byte

in the function "uploadfile" to

Dim myarray(myfile.ContentLength - 1) As Byte

--- CAUSE ---
In the grammar of VB.NET, vb6 or vba, Dim abArray(n) defines an array sized
n+1. In other words, Dim myarray(myfile.ContentLength) declares an array
with (myfile.ContentLength + 1) elements and result in an extra byte at the
end of the file. To allocate an array with n elements, we need to use Dim
abArray(n-1)

--- SKILL ---
You may wonder how I found out the problem. I used your code to import &
export a docx file. The resulting docx cannot be opened, thus I used a
binary editor to compare the two docx. To my surprise, the resulting one
always has an extra byte (00) in the end. If I remove the byte, it opens
fine. That said, if we can determine where the extra byte is getting added
(import or export), we should be set. I started with the import procedure.
The source docx for test contained 1069bytes (it's deteced from my binary
editor). I saw the code myfile.ContentLength return 1069 as expected,
however, in.Parameters(4).Value = myarray, I detected that myarray
contained 1070 elements. Then I know where the problem is.

You may also wonder why the problem did not occur to the doc files. It's
because doc and docx have completely different file formats (see
http://msdn.microsoft.com/en-us/library/aa338205.aspx). Microsoft Word uses
different parser for the two files. The parser of doc does not regards the
extra 00 byte at the end of the file as a mistake. But the parser of docx
does.

Haim, please try the solution and let me know whether it works for you or
not. If you have any other questions or concerns, please DON'T hesitate to
tell me.

P.S.
I notice that you once posted this question in the
microsoft.public.office.developer.officedev.other newsgroup a few weeks
ago. Our managed newsgroup system did not capture that post and we
(Microsoft) did not jump in because
microsoft.public.office.developer.officedev.other is not a managed
newsgroup. For the list of queues that are managed by us, please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa974230.aspx.

Regards,
Jialiang Ge (jialge@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • RE: DCOM Process Launcher hung
    ... Microsoft CSS Online Newsgroup Support ... This newsgroup only focuses on SBS technical issues. ... | Thread-Topic: DCOM Process Launcher hung ...
    (microsoft.public.windows.server.sbs)
  • RE: Help & Support
    ... I will be here waitting for your updates. ... Microsoft CSS Online Newsgroup Support ... This newsgroup only focuses on SBS technical issues. ...
    (microsoft.public.windows.server.sbs)
  • Re: Monitoring and Alerts
    ... A suggestion would be to contact Microsoft Product Support Services via ... Microsoft CSS Online Newsgroup Support ... This newsgroup only focuses on SBS technical issues. ... |> Regarding CEICW, do you mean you can not run CEICW successfully now? ...
    (microsoft.public.windows.server.sbs)
  • RE: VPN attempt gives error 733 at the client
    ... I recommend you contact CSS for better support for saving your time. ... Microsoft CSS Online Newsgroup Support ...
    (microsoft.public.windows.server.sbs)
  • Re: Monitoring and Alerts
    ... Microsoft CSS Online Newsgroup Support ... In Server Management, expand Advanced Management\Group Policy ...
    (microsoft.public.windows.server.sbs)

Loading