首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

附件在线预览解决思路

2012-09-16 
附件在线预览asp.net如何实现附件的在线预览啊?要求:什么格式的都有,能够打开的可以预览(txt,doc...),不能

附件在线预览
asp.net如何实现附件的在线预览啊?
要求:什么格式的都有,能够打开的可以预览(txt,doc...),不能够打开的可以不预览(rar)
            一边显示缩略图,一边显示当前选中的缩略图的文件
最好是有现成的控件或源码的。

希望各位帮帮忙

[解决办法]

C# code
using System;  using System.Data;  using System.Configuration;  using System.Collections;  using System.Web;  using System.Web.Security;  using System.Web.UI;  using System.Web.UI.WebControls;  using System.Web.UI.WebControls.WebParts;  using System.Web.UI.HtmlControls;  using System.IO;  using System.Diagnostics;  using Word = Microsoft.Office.Interop.Word;  using Excel = Microsoft.Office.Interop.Excel;  using System.Reflection;  using Microsoft.Office.Interop.Excel;      public partial class upload_preview : System.Web.UI.Page  {      protected void Page_Load(object sender, EventArgs e)      {            GenerationWordHTML("E://20110502.doc", "E://20110502.html");          GenerationExcelHTML("E://20110502.xls", "E://20110502.html");      }        /// <summary>      /// Ecxel文件生成HTML并保存      /// </summary>      /// <param name="FilePath">需要生成的ecxel文件的路径</param>      /// <param name="saveFilePath">生成以后保存HTML文件的路径</param>      /// <returns>是否生成成功,成功为true,反之为false</returns>      protected bool GenerationExcelHTML(string FilePath, string saveFilePath)      {          try          {              Excel.Application app = new Excel.Application();              app.Visible = false;              Object o = Missing.Value;                ///打开文件              /*下面是Microsoft Excel 9 Object Library的写法: */              /*_Workbook xls = app.Workbooks.Open(FilePath, o, o, o, o, o, o, o, o, o, o, o, o);*/                /*下面是Microsoft Excel 10 Object Library的写法: */              _Workbook xls = app.Workbooks.Open(FilePath, o, o, o, o, o, o, o, o, o, o, o, o, o, o);                ///转换格式,另存为 HTML              /*下面是Microsoft Excel 9 Object Library的写法: */              /*xls.SaveAs(saveFilePath, Excel.XlFileFormat.xlHtml, o, o, o, o, XlSaveAsAccessMode.xlExclusive, o, o, o, o);*/                /*下面是Microsoft Excel 10 Object Library的写法: */              xls.SaveAs(saveFilePath, Excel.XlFileFormat.xlHtml, o, o, o, o, XlSaveAsAccessMode.xlExclusive, o, o, o, o, o);                ///退出 Excel              app.Quit();              return true;          }          catch          {              return false;          }          finally          {              //最后关闭打开的excel 进程              Process[] myProcesses = Process.GetProcessesByName("EXCEL");              foreach (Process myProcess in myProcesses)              {                  myProcess.Kill();              }          }      }        /// <summary>      /// WinWord文件生成HTML并保存      /// </summary>      /// <param name="FilePath">需要生成的word文件的路径</param>      /// <param name="saveFilePath">生成以后保存HTML文件的路径</param>      /// <returns>是否生成成功,成功为true,反之为false</returns>      private bool GenerationWordHTML(string FilePath, string saveFilePath)      {          try          {              Word.ApplicationClass word = new Word.ApplicationClass();              Type wordType = word.GetType();              Word.Documents docs = word.Documents;                /// 打开文件               Type docsType = docs.GetType();              Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { FilePath, true, true });                /// 转换格式,另存为 HTML               Type docType = doc.GetType();                /*下面是Microsoft Word 9 Object Library的写法: */              /*docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFilePath, Word.WdSaveFormat.wdFormatHTML });*/                /*下面是Microsoft Word 10 Object Library的写法: */              docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,              null, doc, new object[] { saveFilePath, Word.WdSaveFormat.wdFormatFilteredHTML });                /// 退出 Word              wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);              return true;          }          catch          {              return false;          }          finally          {              //最后关闭打开的winword 进程              Process[] myProcesses = Process.GetProcessesByName("WINWORD");              foreach (Process myProcess in myProcesses)              {                  myProcess.Kill();              }          }      }  } 


[解决办法]
没。
上传图片浏览到是可以

热点排行