无为清净楼资源网 Design By www.qnjia.com
1.功能说明
输入文件路径,在浏览器输出文件预览信息,经测试360极速(Chrome)、IE9/10、Firefox通过
2.分类文件及代码说明
DemoFiles 存放可测试文件
Default.aspx 启动页
ExcelPreview.cs Excel预览类
public static void Priview(System.Web.UI.Page p, string inFilePath, string outDirPath = "") { Microsoft.Office.Interop.Excel.Application excel = null; Microsoft.Office.Interop.Excel.Workbook xls = null; excel = new Microsoft.Office.Interop.Excel.Application(); object missing = Type.Missing; object trueObject = true; excel.Visible = false; excel.DisplayAlerts = false; string randomName = DateTime.Now.Ticks.ToString(); //output fileName xls = excel.Workbooks.Open(inFilePath, missing, trueObject, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //Save Excel to Html object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml; Workbook wsCurrent = xls;//(Workbook)wsEnumerator.Current; String outputFile = outDirPath + randomName + ".html"; wsCurrent.SaveAs(outputFile, format, missing, missing, missing, missing, XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing); excel.Quit(); //Open generated Html Process process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.FileName = outputFile; process.Start(); }
4.PDfPreview.cs Pdf预览类
public static void Priview(System.Web.UI.Page p, string inFilePath) { p.Response.ContentType = "Application/pdf"; string fileName = inFilePath.Substring(inFilePath.LastIndexOf('\\') + 1); p.Response.AddHeader("content-disposition", "filename=" + fileName); p.Response.WriteFile(inFilePath); p.Response.End(); }
5.TextFilePreview.cs 文本文件预览类
public static void Preview(System.Web.UI.Page p, string inFilePath) { string fileName = inFilePath.Substring(inFilePath.LastIndexOf('\\') + 1); p.Response.ContentType = "text/plain"; p.Response.ContentEncoding = System.Text.Encoding.UTF8; //保持和文件的编码格式一致 p.Response.AddHeader("content-disposition", "filename=" + fileName); p.Response.WriteFile(inFilePath); p.Response.End(); }
6. WordPreview.cs Word预览类
7.Readme.txt 说明了基本功能及引用Com组件的方法(首先需要安装office),需引入的组件包括
Microsoft Word 15.0
Microsoft Excel 15.0
预览效果
1、Word
2、Excel
3、Pdf
4、Txt
未解决的问题
Pdf、txt文件只能在当前页显示,并导致后退键无效,请各位帮忙解决此两种文件和doc、xls一样在新的tab中打开
5.源码下载:http://xiazai.jb51.net/201612/yuanma/FilePreviewInBrowser_jb51.rar
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
标签:
asp.net,预览,文件
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月27日
2024年09月27日
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】
- 赞多《序章》[FLAC/分轨][129.13MB]
- 群星《完美的她 影视原声带》[320K/MP3][51.98MB]
- 群星《完美的她 影视原声带》[FLAC/分轨][141.05MB]
- 山风点伙.1997-深藏不露【立得】【WAV+CUE】
- 李幸倪.2018-First.Of.All.Live.Concert.3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】
- 群星《你就在我身边 电影原声专辑》[320K/MP3][26.68MB]
- 群星《你就在我身边 电影原声专辑》[FLAC/分轨][70.27MB]
- 班得瑞原装进口《20周年精选集》1CD[APE/CUE分轨][303MB]
- 群星.2009-NOON.D.广东.2CD【新世纪】【WAV+CUE】
- 洪卓立.2012-GROWN.UP【英皇娱乐】【WAV+CUE】