ASP.NET----实现网页中查看offic文件,word,ppt等
2011-05-13 19:24
375 查看
原理很简单,实现一个树,先获取文件存放文件夹地址,然后遍历每个文档,填入到树节点中去,看下截图效果:
具体看下面代码:
File.cs:
页面布局:
具体看下面代码:
File.cs:
public partial class Files : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if(!this.IsPostBack) this.InitTree(); } private void InitTree() { //清除树节点 this.trvFiles.Nodes.Clear(); //实例化根节点 TreeNode node = new TreeNode(); node.Text = "简历文件"; node.Value = ""; //获取存放Word PPT文件的文件夹路径 string dicPath = this.Server.MapPath("WordFiles"); //实例化文件夹对象 DirectoryInfo dic = new DirectoryInfo(dicPath); //循环获取Word文档文件 foreach (FileInfo file in dic.GetFiles("*.doc")) { //实例化文件节点 TreeNode fileNode = new TreeNode(); //赋值 fileNode.Text = file.Name; fileNode.Value = file.FullName; //添加至根节点中 node.ChildNodes.Add(fileNode); continue; } //循环获取PPT文件 foreach (FileInfo file in dic.GetFiles("*.ppt")) { TreeNode fileNode = new TreeNode(); fileNode.Text = file.Name; fileNode.Value = file.FullName; node.ChildNodes.Add(fileNode); continue; } //展开文件夹节点 node.Expand(); this.trvFiles.Nodes.Add(node); } protected void trvFiles_SelectedNodeChanged(object sender, EventArgs e) { //判断选中节点不是根节点 if (!string.IsNullOrEmpty(this.trvFiles.SelectedNode.Value)) { //拼装打开文件的JavaScript脚本 string js = "window.frames[0].location.href='{0}';"; js = string.Format(js, "WordFiles/" + this.trvFiles.SelectedNode.Text); //执行脚本 即在DocShow.aspx页面打开相应节点 this.WriteJS(js); } } protected void WriteJS(string msg) { string script = string.Format("<script type='text/javascript' language='javascript'>{0}</script>", msg); this.ClientScript.RegisterStartupScript(this.GetType(), "alert", script); } protected void AlertMsg(string msg) { string script = string.Format("<script type='text/javascript' language='javascript'>window.alert('{0}');</script>",msg); this.ClientScript.RegisterStartupScript(this.GetType(),"alert",script); } }
页面布局:
<body> <form id="form1" runat="server"> <div> <table style="border: none; padding: none; margin: none; width: 100%; height: 100%;"> <tr> <td style="width:20%;height:100%;vertical-align:top;"> <asp:TreeView ID="trvFiles" runat="server" ImageSet="XPFileExplorer" NodeIndent="15" OnSelectedNodeChanged="trvFiles_SelectedNodeChanged"> <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" /> <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px" VerticalPadding="0px" /> <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px" /> </asp:TreeView> </td> <td> <iframe style="scroll:auto;width:100%;height:800px;border:none;" src="DocShow.aspx"> </iframe> </td> </tr> </table> </div> </form> </body> 网盘下载:http://u.115.com/file/clia1ceu
相关文章推荐
- Asp.net MVC 利用(aspose+pdfobject.js) 实现在线预览word、excel、ppt、pdf文件
- ASP.NET中实现直接从网页上下载文件,而不须引用文件URL来下载
- ASP.NET中实现直接从网页上下载文件,而不须引用文件URL来下载
- Asp.net实现直接在浏览器预览Word、Excel、PDF、Txt文件(附源码)
- asp.net实现word文档在线查看功能 (三种方法)
- Asp.Net实现生成WORD或PDF文件
- Asp.net实现直接在浏览器预览Word、Excel、PDF、Txt文件(附源码)
- ASP.NET中实现导出ppt文件数据的实例分享
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
- ASP.NET实现WORD文件自动转换PDF
- .net 实现Office文件预览,word文件在线预览、excel文件在线预览、ppt文件在线预览,excel转html,office格式转换,
- ASP.NET中实现直接从网页上下载文件
- asp.net实现word、excel、ppt、pdf在线预览
- 拥有网页版小U盘 ASP.NET实现文件上传与下载功能
- 拥有网页版小U盘 ASP.NET实现文件上传与下载功能
- asp.net 文件下载(txt,rar,pdf,word,excel,ppt)
- asp.net网页中上传并且浏览pdf文件的实现
- ASP.NET中实现直接从网页上下载文件
- ASP.NET 2.0实现类似QQ邮箱中‘HTML方式查看’功能查看Office文件
- Asp.net实现直接在浏览器预览Word、Excel、PDF、Txt文件(附源码)