如何上传word文档并在c#中显示 [英] how to upload word document and show it in c#

查看:209
本文介绍了如何上传word文档并在c#中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个word文档,我该如何存储并检索它





我可以将文档存储在项目和路径它的数据库,然后如何resiv那个word文档然后

i have a word document ,how can i store it and retrieve it


can i do like storing the document in the project and path it database ,then how to restive that word document then

推荐答案

您可以以BLOB格式或目录存储文件,以在ASP中显示word文档。 NET你需要使用Response对象

见下面的代码片段

You can store file either in BLOB format or in directory, to show word document in ASP.NET you need to use Response object
see below snippet
//store file in DB
public static void databaseFilePut(string varFilePath) {
    byte[] file;
    using (var stream = new FileStream(varFilePath, FileMode.Open, FileAccess.Read)) {
        using (var reader = new BinaryReader(stream)) {
            file = reader.ReadBytes((int) stream.Length);       
        }          
    }
    using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetails))
    using (var sqlWrite = new SqlCommand("INSERT INTO TABLE1(COL1) Values(@File)", varConnection)) {
        sqlWrite.Parameters.Add("@File", SqlDbType.VarBinary, file.Length).Value = file;
        sqlWrite.ExecuteNonQuery();
    }
}



此处列数据类型应为 VARBINARY(MAX)

IFRAME是一个很好的控件,可以在浏览器中显示word文件,或者如果你不希望你的文件被编辑,你可以将它保存为HTML并显示它


Here the column datatype should be VARBINARY(MAX)
IFRAME is a nice control to show word file in browser, Or if you don't want your file to get edit you can save it as HTML and the show it


这篇关于如何上传word文档并在c#中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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