asp.net将word转换为html保存

    技术2022-05-11  61

     

    using  System; using  System.Collections; using  System.ComponentModel; using  System.Web; using  Word; namespace  Rules {    ///     /// 将word文档上传至服务器然后再转存为html格式文件    /// 再解析html文件修改其页面样式和css    /// BlackSoul 2005.11.08    ///     public class WordToHTML    {        public WordToHTML() { }        上传文件并转换为html wordToHtml(wordFilePath)        public string uploadWord(System.Web.UI.HtmlControls.HtmlInputFile uploadFiles)        {            if (uploadFiles.PostedFile != null)            {                string fileName = uploadFiles.PostedFile.FileName;                int extendNameIndex = fileName.LastIndexOf(".");                string extendName = fileName.Substring(extendNameIndex);                string newName = "";                try                {                    //验证是否为word格式                    if (extendName == ".doc")                    {                        DateTime now = DateTime.Now;                        newName = now.DayOfYear.ToString() + uploadFiles.PostedFile.ContentLength.ToString();                        //上传路径 指当前上传页面的同一级的目录下面的wordTmp路径                        uploadFiles.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName));                    }                    else                    {                        return "1";                    }                }                catch                {                    return "0";                }                //return "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath + "/wordTmp/" + newName + extendName;                return System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName);            }            else            {                return "0";            }        }    }}

    最新回复(0)