损坏的文件 Microsoft Office 2007 ASP.NET 1.1 和 SQL Server

发布于 2024-11-28 17:12:52 字数 483 浏览 0 评论 0原文

我正在开发一个 ASP.NET 1.1 网站,该网站将文件存储在数据库中。自 2001 年以来,该网站一直运行良好,上传和下载任何类型的文档都没有问题。

但是,最近客户注意到所有 Microsoft Office 2007 文档 DOCXXLSX 等当任何用户尝试下载它们时,它们都会被损坏。

我注意到 SQL Server 在 DocumentContent (图像列)中添加了一个额外的字节。在上传文档之前,内容和长度都很好。然而,在它们被存储之后,SQL Server 会添加一个额外的字节......为什么??????

互联网上的许多人提供了如何下载该文件的解决方案,这很棒并且对我有用。

我正在寻找这个问题的答案...为什么 SQL SERVER 向图像列添加额外的字节?

它是 Asp.NET 1.1 和 SQL 2000,但我们刚刚将其移至 2008 年,但仍然存在相同的问题。

I am working on an ASP.NET 1.1 website that stores files in the database. The website has been working great with no problems uploading and downloading any type of documents since 2001.

However, recently the customer noticed that all Microsoft Office 2007 documents DOCX, XLSX, ect are corrupted when any user try to download them.

What I have noticed is that SQL Server adds an extra byte to the DocumentContent (image column). Before uploading the document the content and length are fine. However, after they get stored, SQL Server adds an EXTRA Byte.... WHY?????

Many people on the internet provided a solution on how to download the file, which is great and it worked for me.

I am looking for an answer to this question... WHY DOES SQL SERVER ADD AN EXTRA BYTE TO THE IMAGE COLUMN?

It is an Asp.NET 1.1 and SQL 2000 but we just moved it to 2008 and we still have the same problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2024-12-05 17:12:52

我不能 100% 确定您的问题是否与我遇到的问题相同,但就我而言,我发现问题实际上是在写作部分,而不是在阅读部分。例如,我原来的编写代码是这样的:

Dim FILE_CONTENT(len) As Byte
File.InputStream.Read(FILE_CONTENT, 0, len)
SaveFileToDatabase(FILE_NAME, CONTENT_TYPE, FILE_CONTENT)

当我将第一行更改为以下内容时:

Dim FILE_CONTENT(0 To len - 1) As Byte 

读取错误消失了。我只是忘记了,当您在没有指定下限的情况下确定尺寸时,VB 实际上默认分配 N+1 个字节(O 到 N)。请参阅此处描述的类似情况:上传的 Docx 文件已损坏。希望有帮助。

I am not 100% sure if your problem was the same as what I have had but in my case, I found that the problem was actually in the writing part, not in the reading part. For example, my original writing code was like this:

Dim FILE_CONTENT(len) As Byte
File.InputStream.Read(FILE_CONTENT, 0, len)
SaveFileToDatabase(FILE_NAME, CONTENT_TYPE, FILE_CONTENT)

When I changed the first line as the following :

Dim FILE_CONTENT(0 To len - 1) As Byte 

the reading error disappeared. I just forgot that VB actually allocates N+1 bytes (O to N) by default when you dimension it without specifying the lower bound. See similar situation described here: Uploaded Docx Files are getting corrupted . Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文