asp.net将word转换为html保存

来源:互联网 发布:2015中国外汇储备数据 编辑:程序博客网 时间:2024/05/22 16:42
很久以前写的了..发在blogger上的.结果blogger被封..现在解封了.转回来.
  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/wordtohtml.html

原创粉丝点击