gpt4 book ai didi

c# - 我应该如何将 .doc 文档保存到 SQL Server 数据库

转载 作者:行者123 更新时间:2023-11-30 17:14:55 25 4
gpt4 key购买 nike

我使用下面的 C# 代码将 .doc 文件保存到 SQL Server 数据库中作为 varbinary(max)

我可以保存文件,但是当我取回文件并想在网页上显示内容时,我的代码正在下载文件,我很困惑如何处理它。

我正在寻找的确切功能是 naukri.com 的方式上传简历并预览。我的代码是:

byte[] fileContent = new byte[fuResume.PostedFile.ContentLength];
fuResume.PostedFile.InputStream.Read(fileContent, 0, fuResume.PostedFile.ContentLength);
//lblAppliedMessage.Text = ByteArrayToString(fileContent);

//lblAppliedMessage.Text = BitConverter.ToString(fileContent).Replace("-", string.Empty);
byte[] btYourDoc;
btYourDoc = fileContent;

Response.ContentType = "application/ms-word";
Response.AddHeader("Content-Disposition", "inline;filename=yourfilename.doc");
Response.OutputStream.Write(btYourDoc, 0, fileContent.Length);

Response.BinaryWrite(btYourDoc);

Response.End();

最佳答案

您的文件被下载而不是显示的原因是因为您将内容类型设置为应用程序/ms-word。这会告诉浏览器下载文件(它们本身无法处理该类型的文件,因此它们委托(delegate)给外部应用程序)。

您需要拥有知道如何解释 MS Word 格式并将其转换为可在浏览器中查看的内容(HTML、某种可以为您执行此操作的插件等)的代码。保存原始 Word 文档,然后以相同的状态将其发送回客户端基本上只是让他们下载一个 Word 文件。

关于c# - 我应该如何将 .doc 文档保存到 SQL Server 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8333384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com