热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->net 
站内搜索:
asp.net将word转换为html保存
作者:BlackSoul 来源:blog 整理日期:2007-5-19

  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4using System.Web;
  5using Word;
  6
  7namespace Rules
  8{
  9/// 
 10/// 将word文档上传至服务器然后再转存为html格式文件
 11/// 再解析html文件修改其页面样式和css
 12/// BlackSoul 2005.11.08
 13/// 

 14public class WordToHTML
 15{
 16public WordToHTML(){}
 17
 18上传文件并转换为html wordToHtml(wordFilePath)
 82
 83public string uploadWord(System.Web.UI.HtmlControls.HtmlInputFile uploadFiles)
 84{
 85if(uploadFiles.PostedFile != null)
 86{
 87string fileName = uploadFiles.PostedFile.FileName ;
 88int extendNameIndex= fileName.LastIndexOf(".");
 89string extendName = fileName.Substring(extendNameIndex);
 90string newName = "";
 91try
 92{
 93//验证是否为word格式
 94if(extendName == ".doc")
 95{
 96
 97DateTime now = DateTime.Now;
 98newName = now.DayOfYear.ToString()+uploadFiles.PostedFile.ContentLength.ToString();
 99//上传路径 指当前上传页面的同一级的目录下面的wordTmp路径
100uploadFiles.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName));
101}

102else
103{
104return "1";
105}

106}

107catch
108{
109return "0";
110}

111//return "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.
Request.ApplicationPath + "/wordTmp/" + newName + extendName;

112return System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName);
113}

114
115else
116{
117return "0";
118}

119}

120
121}

122}

原文地址:

http://www.cnblogs.com/BlackSoul/archive/2006/09/30/519322.aspx

相关文章