我应该如何进行的.doc文件保存到一个SQL Server数据库 [英] How should I be saving .doc documents to a SQL Server database

查看:196
本文介绍了我应该如何进行的.doc文件保存到一个SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的是C#code以下保存.doc文件到SQL Server数据库 VARBINARY(最大)

我能保存文件,但是当我检索文件回来,想在网页上显示的内容,我的code是下载文件,我在如何处理它很大的混乱。

我要寻找的确切功能的方式 naukri.com 上传简历,并给出了preVIEW它。我的code是:

 字节[] = fileContent新的字节[fuResume.PostedFile.ContentLength]
fuResume.PostedFile.InputStream.Read(fileContent,0,fuResume.PostedFile.ContentLength);
//lblAppliedMessage.Text = ByteArrayToString(fileContent);//lblAppliedMessage.Text = BitConverter.ToString(fileContent).Replace( - ,的String.Empty);
字节[] btYourDoc;
btYourDoc = fileContent;Response.ContentType =应用程序/ MS-词;
Response.AddHeader(内容处置,内联;文件名= yourfilename.doc);
Response.OutputStream.Write(btYourDoc,0,fileContent.Length);Response.BinaryWrite(btYourDoc);到Response.End();


解决方案

squillman是正确的。有吨是做文字第三方组件 - > HTML转换。

另外一种选择,这可能是更适合于Intranet站点,是在服务器上安装Word。

这方面的一个例子是在这里:

http://www.c-sharpcorner.com/UploadFile/munnamax/WordToHtml03252007065157AM/WordToHtml.aspx

实际上,该文档被打开,被救出来为HTML,那么随后的请求可以检索preVIEW文件的HTML版本。

办公自动化服务器端有很多陷阱,但是 - 见 http://support.microsoft.com/kb / 257757 了解详情。

I am saving a .doc file to a SQL Server database as varbinary(max) using the C# code below.

I am able to save the file, but when I retrieve the file back and want to display the contents on the web page, my code is downloading the file and I am in great confusion about how to handle it.

The exact functionality I am looking for is the way naukri.com uploads the resume and gives a preview of it. My code is :

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();

解决方案

squillman is right. There are tons of third party components that do Word -> HTML conversion.

One other option, which may be more appropriate for an intranet site, is to install Word on the server.

An example of this is here:

http://www.c-sharpcorner.com/UploadFile/munnamax/WordToHtml03252007065157AM/WordToHtml.aspx

Effectively, the doc is opened, saved out as HTML, then subsequent requests can retrieve the HTML version of the file for preview.

Office automation server side has many pitfalls, however - see http://support.microsoft.com/kb/257757 for more information.

这篇关于我应该如何进行的.doc文件保存到一个SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆