本人小白一个,初次接触C#,各位大神还请多多点出不足,谢谢!

项目需求是:User将PPT文件上传后,公司大厅电视看板内容随即改变为上传PPT文件内容,并进行轮播显示

思路:1,实现将PPT文件打开并转换成图片保存

2,每次PPT文件内容大小不定,即转换成图片数量不定

3,转换成的图片名称不可一致,因为浏览器具有缓存功能

废话不说,上代码:

aspx代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="One.aspx.cs" Inherits="First" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="refresh" content="5"><title></title><style type="text/css">html,body{height:100%;width:100%;margin:0px;padding:0px;}#maindiv{height:100%;width:100%;margin:0px;padding:0px;}</style>
//电视看板当然需要全屏显示,所以需要进行自适应设置<script type="text/javascript">window.onload = function () {var table = document.getElementById('table');table.style.width = document.documentElement.clientWidth + 'px';table.style.height = document.documentElement.clientHeight + 'px';}</script>
</head>
<body overflow:-Scroll;overflow-y:hidden;overflow-x:hidden><form id="form1" runat="server"><div id="table"><div runat ="server" id ="maindiv" style =" border-width:0px;"/>  </div></form>
</body>
</html>

后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Timers;
using System.Threading;
using System.IO;public partial class First : System.Web.UI.Page
{   protected void Page_Load(object sender, EventArgs e){DirectoryInfo dirInfo = new DirectoryInfo(System.AppDomain.CurrentDomain.BaseDirectory + "1Img\\");FileInfo[] files = dirInfo.GetFiles();int length = files.Length;//获取文件间中的文件数量if (Session["f"] == null){Session["f"] = 0;}//创建image控件Session["f"] = int.Parse(Session["f"].ToString()) + 1;this.maindiv.Controls.Clear();Image image = new Image();foreach (var file in files)image.ImageUrl = "1Img/" + file.ToString().Substring(0, 17) + Session["f"].ToString() + ".png";image.ID = "" + Session["f"].ToString() + "image";image.Style["width"] = "100%";image.Style["height"] = "100%";this.maindiv.Controls.Add(image);if (int.Parse(Session["f"].ToString()) >= length){Session["f"] = 0;}}
}

以上代码实现的是看板抓取指定文件夹中的图片Show到电视看板上

下面代码为将上传的PPT文件转换成图片保存如指定文件中:

aspx代码:

(引用<iframe>标签,方便User上传文件后,可以直接在当前页面看到上传后的内容是否正确)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Maintain.aspx.cs" Inherits="Maintain" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="refresh" content="30"><title>Maintain</title><style type="text/css">body,html,div{margin: 0px;padding:0px;}#all,span{width: 90%;height: 90%;padding:5% 5% 0 5%;}iframe{width:32%;}#form1{}</style><script type="text/javascript">window.onload = function () {var href = window.location.href.toString();var The = href.charAt(11);if (The == '9') {this.location.href = 'http://10.99.106.8:8080';}else {this.location.href = 'http://172.31.48.8:8080';}console.log(href)}</script>
</head>
<body><form action="" method="post" runat="server"><div id="all"><iframe src="http://10.99.106.211/WYF/One.aspx" frameborder="0" height="270px" ></iframe><iframe src="http://10.99.106.211/WYF/Two.aspx" frameborder="0" height="270px" ></iframe><iframe src="http://10.99.106.211/WYF/Three.aspx" frameborder="0" height="270px" ></iframe><iframe src="http://10.99.106.211/WYF/Four.aspx" frameborder="0" height="270px" ></iframe><iframe src="http://10.99.106.211/WYF/Five.aspx" frameborder="0" height="270px" ></iframe><iframe src="http://10.99.106.211/WYF/Six.aspx" frameborder="0" height="270px" ></iframe></div><div align="center"><asp:FileUpload ID="FileUpload1" runat="server"   BorderColor="#FF3399" Font-Size="20px"/><asp:Button  ID="Button1" runat="server" Text="上传"  οnclick="Button1_Click"style="width:100px;height:40px" Font-Size="20px"/><asp:Label ID="Label1" runat="server"  Font-Size="20px" ForeColor="Red" Text=""></asp:Label>   </div></form>
</body>
</html>

后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.IO;public partial class Maintain : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e){}protected void Button1_Click(object sender, EventArgs e){if (FileUpload1.HasFile){string path = System.AppDomain.CurrentDomain.BaseDirectory + "Img\\";if (!(FileUpload1.FileName.EndsWith(".pptx") || FileUpload1.FileName.EndsWith(".PPTX"))){Label1.Text = "上传文件只能是png格式,请重新上传!";return;}//截取上传的文件名string filename = FileUpload1.FileName;string File = filename.Substring(0, 1);//上传之前删除指定该文件中的文件:DirectoryInfo dirInfo = new DirectoryInfo(System.AppDomain.CurrentDomain.BaseDirectory + "" + File + "Img\\");FileInfo[] files = dirInfo.GetFiles();// 获取该目录下的所有文件foreach (FileInfo file in files) {file.Delete();}//将上传文件保存至指定文件夹中FileUpload1.SaveAs(Server.MapPath("~/Img/") + FileUpload1.FileName);Label1.Text = "上传成功!";//将上传的文件转换成图片string pptPath = System.AppDomain.CurrentDomain.BaseDirectory + "Img\\" + File + ".pptx";//PPT文件的路径string imgPath = System.AppDomain.CurrentDomain.BaseDirectory + "" + File + "Img\\";//转换成图片保存的路径Thread.Sleep(2000);var app = new Microsoft.Office.Interop.PowerPoint.Application();var ppt = app.Presentations.Open(pptPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);var index = 0;var fileName = System.IO.Path.GetFileNameWithoutExtension(pptPath);foreach (Microsoft.Office.Interop.PowerPoint.Slide slid in ppt.Slides){++index;slid.Export(imgPath + string.Format(DateTime.Now.ToString("yyyy-MM-dd") +"{0}.png", index.ToString()), "png", 1024, 768);}//释放资源ppt.Close();app.Quit();GC.Collect();}else {Label1.Text = "未上传文件,请确认!!";return;}}
}

本地运行后,不出意外,应该可以成功,但当发布到IIS上后,可能会出现报错:PPT文件无法打开

这个问题搞了好久,百度了很多,添加什么引用啊什么都无效,最后更换其他服务进行发布,最后成功了!

C#将PPT文件转换成图片并轮播展示相关推荐

  1. xml文件转换成图片_怎样能把PDF文件转换成图片?

    我们的日常生活工作中时常碰到pdf与Excel.Word.ppt和jpg等文件格式的转换,有时候由于工作的需要,要把PDF文件转换成图片.并且现在网上的很多素材都是PDF文件格式的,如果我们想要里面的 ...

  2. 怎样快速将PPT文件转换成Word

    Microsoft Office Word是一款强大的文档编辑软件,它可以帮助我们将PPT文件转换成Word文档. 利用Microsoft Office Word,将PPT文件转换成word操作过程如 ...

  3. 两种将ppt文件转换成pdf格式的方法

    对于常接触办公文档的童鞋们来说,应该对pdf文件并不陌生吧,pdf具有跨平台.稳定性.安全性阅读良好等优势,正因为如此,许多企业将pdf作为一种重要的文档因为工作需求常常需要将编辑好的ppt转换成pd ...

  4. c#,将pdf文件转换成图片文件。

    本文采用Adobe Acrobat9.0的COM组件,将Pdf文件的每一页转换成对应的图片文件. 开发环境:VS2010,.Net Framework4.0,Adobe Acrobat9.0. 工程中 ...

  5. xml文件转换成图片_如何把pdf文件转换成图片?

    pdf文件怎么转成JPG图片呢?相信有不少人在迷惑,可能还在想着截图等操作来完成转换,但如果是截图成JPG图片后的效果可能很差,并没有之前pdf文件那么清楚.那这样往往打印出来的效果也不怎么理想,那怎 ...

  6. C#,pdf文件转换成图片文件。

    本文采用Adobe Acrobat9.0的COM组件,将Pdf文件的每一页转换成对应的图片文件. 开发环境:VS2010,.Net Framework4.0,Adobe Acrobat9.0. 工程中 ...

  7. 手机端怎么把PDF格式文件转换成图片

    用过PDF文件的伙伴都知道,PDF文件格式可以将文字.字型.格式.颜色及独立于设备和分辨率的图形图像等封装在一个文件中,是我们工作中会经常用到的一种文件格式.如果是在手机中使用到PDF文件的话,需要将 ...

  8. 手机PDF文件转换成图片教程来了,PDF转换器推荐

    手机PDF文件怎么转换成图片?你还在用截图的方式来将PDF文件转换成图片吗?虽然确实是一种转换的方法,但是使用过的都会发现转换出来的图片清晰度不高,那该如何高清转换呢?今天小编就给大家推荐一个比较好用 ...

  9. 怎么把ppt文件转换成pdf?解决方法有这几种

    想必对于PPT和PDF文件都比较熟悉了呗!那怎么解决将PPT格式转成PDF格式呢? 其实PPT转换成PDF格式的话还是很简单的,部分软件通过另存为命令就可以帮你轻松搞定了,可是要想转回去就没那么简单了 ...

最新文章

  1. UVa11300 Spreading the Wealth(数学问题)
  2. python standard lib_跟Python Standard Library混个脸熟(一)
  3. python请输入_不断提示用户输入Python
  4. .netcore持续集成测试篇之MVC层单元测试
  5. 给定重量上限,背包问题_满足给定重量的袋子的最低成本
  6. 自定义taglib引入失败_小程序拼团总失败?看看微信官方和开发者们怎么说
  7. oracle连接连表查询时,两表的连接字段类型不一致的时候,会导致ora 01722无效数字错误,这时候需要转换...
  8. Python入门--文件的读写,相对路径,绝对路径
  9. sharepoint安装心得-.net与sharepoint安装 sharepoint安装心得_过程(一)
  10. HashMap源码阅读
  11. 天涯明月刀7月5号服务器维护,天涯明月刀7月5日更新_天刀7月5日版本改动_3DM网游...
  12. html 手动添加thead,HTML DOM Table createTHead() 方法
  13. LCC编译器的源程序分析(27)基本语句
  14. 有关企业合并时的10条IT措施
  15. 对《ToonSynth: Example-Based Synthesis of Hand-Colored Cartoon Animations》一文的理解(上)
  16. 计算机维护与维修方法,浅谈计算机维护与维修方法
  17. 计算机office比赛,Office智慧丨“点亮未来”
  18. 关于指数运算,以一有趣的应用题简单展开。
  19. ISO/SAE 21434 标准是什么? 《Road vehicles—Cybersecurity engineering(道路车辆-信息安全工程)》
  20. 测试用例——用户登录

热门文章

  1. 重塑大融合体系,立体推进“业财合一”
  2. 数字电路实验(十二)——CPU综合设计(8)
  3. 机器人辅助的符文天赋_LOLS7辅助机器人 机器人辅助天赋加点攻略
  4. 5.金蝶KIS旗舰版从销售订单下推销售出库单使用说明,金蝶盘点机PDA仓库条码管理
  5. MySQL函数(经典收藏)
  6. 经典网络结构 (六):DenseNet (Densely Connected Networks 稠密连接网络)
  7. 在Mplus安装JAVA_Mplus教程-Mplus安装和入门一文搞定
  8. 无线网服务器mac是什么原因,为何mac连上wifi却上不了网
  9. (旺财记账项目)Vue 全局数据管理(下)之Vuex
  10. 使用Spring Boot Thin Launcher 打包Spring Boot项目,jar包瘦身