首页 新闻 会员 周边

用户上传word文件,直接显示在页面。求写具体点。

0
悬赏园豆:20 [已解决问题] 解决于 2012-04-01 14:19

如题。谢谢.string path = File1.PostedFile.FileName;

            Stream fileStream = File1.PostedFile.InputStream;
            int length = File1.PostedFile.ContentLength;
            byte[] wordData=new byte[length];不会写了。知道后面还要写 Response.ContentType = "application/msword";。但是写出来不是显示在页面上而是成下载样

 

香草DE味道的主页 香草DE味道 | 初学一级 | 园豆:112
提问于:2012-04-01 11:55
< >
分享
最佳答案
0

下面是直接向WORD文件转成HTML页面的方法,不知道是不是您想要的效果

 ///<summary>
/// 根据MSWord文件,生成Html文件
///</summary>
///<param name="wordFilePath">Word文件路径(绝对)</param>
///<param name="htmlFilePath">生成的Html文件路径(绝对),路径的目录结构必须存在,否则保存失败</param>
///<returns>是否执行成功</returns>
public static bool MSWordToHtml(string wordFilePath, string htmlFilePath)
{
//using Microsoft.Office.Interop.Word;
ApplicationClass wordApp = new ApplicationClass();
Type wordType = wordApp.GetType();

Documents docs = wordApp.Documents;
Type docsType = docs.GetType();

try
{
Document doc = (Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs,
new Object[] { wordFilePath, true, true });
Type docType = doc.GetType();
docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc,
new object[] { htmlFilePath, WdSaveFormat.wdFormatFilteredHTML });
return true;
}
catch
{
return false;
}
finally
{
wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, wordApp, null);
}
}
收获园豆:10
八戒的师傅 | 小虾三级 |园豆:1472 | 2012-04-01 13:29

额,不是只是一个FileUpload下上传一个word文件,想要显示在页面。

香草DE味道 | 园豆:112 (初学一级) | 2012-04-01 13:44

@香草DE味道: 你是要达到百度文库 类似的效果吧?

八戒的师傅 | 园豆:1472 (小虾三级) | 2012-04-01 13:52

@八戒的师傅: 嗯差不多。有例子给看看吗?

香草DE味道 | 园豆:112 (初学一级) | 2012-04-01 13:55

@香草DE味道: 百度文档使用的应该是Flex技术实现的,微软平台下的Silverlight应该也可以实现类似的效果,具体可以百度一下Flex和FlexPaper的相关信息,也可以参考以下开源工作社区的介绍:
http://www.oschina.net/p/flexpaper/

八戒的师傅 | 园豆:1472 (小虾三级) | 2012-04-01 14:03
其他回答(3)
0

试试下面的代码:

Response.ContentType = "application/msword";
Response.WriteFile(FilePath);
收获园豆:5
dudu | 园豆:30994 (高人七级) | 2012-04-01 12:02

你的意思是只打这两句话?string path = File1.PostedFile.FileName; Response.ContentType = "application/msword"; Response.WriteFile(path);结果是未能找到文件“C:\Users\Administrator\documents\visual studio 2010\Projects\TestForF\TestForF\wocao.docx”。不行呀

支持(0) 反对(0) 香草DE味道 | 园豆:112 (初学一级) | 2012-04-01 13:40
0

是要像百度文库那样,可以显示word文档吗?

收获园豆:5
吕飞 | 园豆:280 (菜鸟二级) | 2012-04-01 12:40

嗯差不多。

支持(0) 反对(0) 香草DE味道 | 园豆:112 (初学一级) | 2012-04-01 13:54
0

这个问题现在早有非常成熟的方案了,用卓正PageOffice,在线显示编辑word、excel,不费吹灰之力,跨浏览器支持,IE、谷歌Chrome、火狐Firefox、Opera、国产浏览器兼容极速模式都不在话下

spiderman3 | 园豆:210 (菜鸟二级) | 2013-06-28 15:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册