使用 ASP.Net 将存储在 SQL Server 中的 MS Office 文件直接保存到服务器目录

发布于 2024-08-08 19:32:32 字数 386 浏览 1 评论 0原文

我正在 SQL Server 中存储 MS Office 文件,例如 PowerPoint(.ppt、.pptx)和 Word(.doc、.docx),并且需要通过 ASP.Net 应用程序将这些文件保存到服务器上的临时文件目录。我从数据库中获取文件并以字节数组的形式放入应用程序中。但我不知道如何将字节数组保存为指定目录位置中适当格式(.ppt/.pptx 等)的文件。

我知道我可以使用代码将 Response.ContentType 设置为“application/ms-word”之类的内容,然后将 Response.AddHeader 的“content-disposition”设置为“attachment”。但是,这会打开一个“另存为”对话框。我需要做的是将文件直接保存到服务器上的目录中(以便我可以对其进行一些进一步的操作)。

I am storing MS Office files such as PowerPoint (.ppt, .pptx) and Word (.doc, .docx) in SQL Server, and need to save these files to a temp file directory on the server through an ASP.Net application. I get the files up from the database and into the application as a Byte Array. But what I don’t know is how to then save the Byte Array as a file in the appropriate format (.ppt/.pptx etc) in a specified directory location.

I know that I can use code along the lines of setting the Response.ContentType to something like "application/ms-word", and then setting the “content-disposition” of Response.AddHeader to “attachment”. However, this opens a “save as” dialog. What I need to do is to save the file directly into a directory on the server (so that I can do some further operations on it).

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

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

发布评论

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

评论(1

可爱咩 2024-08-15 19:32:32

你只需要这个:

File.WriteAllBytes(
     Path.Combine(Server.MapPath("/temp_folder"), "YourFileName.ext"),
     yourByteArray);

You just need this:

File.WriteAllBytes(
     Path.Combine(Server.MapPath("/temp_folder"), "YourFileName.ext"),
     yourByteArray);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文