通过TreeView管理图片文件夹

程序运行效果如下图所示:

代码比较简单内容如下:

usingSystem; usingSystem.Data; usingSystem.Configuration; usingSystem.Collections; usingSystem.Web; usingSystem.Web.Security; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; usingSystem.Web.UI.WebControls.WebParts; usingSystem.Web.UI.HtmlControls; usingSystem.IO; publicpartialclassDefault12:System.Web.UI.Page ...{ publicTreeViewtv=newTreeView(); protectedvoidPage_Load(objectsender,EventArgse) ...{ if(!Page.IsPostBack) ...{ showTree(); } } protectedvoidButton1_Click(objectsender,EventArgse) ...{ foreach(TreeNodetninTreeView1.CheckedNodes) ...{ File.Delete(tn.Value); } } protectedvoidshowTree() ...{ TreeView1.Nodes.Clear(); TreeNodetn; TreeView1.Nodes.Add(newTreeNode("图片管理TreeView")); foreach(FileInfofileinnewDirectoryInfo(Server.MapPath("~/image")).GetFiles()) ...{ tn=newTreeNode(file.Name,file.FullName); TreeView1.FindNode("图片管理TreeView").ChildNodes.Add(tn); TreeView1.ExpandAll(); } } protectedvoidTreeView1_TreeNodeCheckChanged(objectsender,TreeNodeEventArgse) ...{ Response.Write("thiseventontreeview1checkchanged!"); } protectedvoidTreeView1_SelectedNodeChanged(objectsender,EventArgse) ...{ Image1.ImageUrl=@"image/"+Path.GetFileName(TreeView1.SelectedNode.Value); } }

前台代码:

<%...@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default12.aspx.cs"Inherits="Default12"%> <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml"> <headrunat="server"> <title>文件管理</title> </head> <body> <formid="form1"runat="server"> <div> <asp:TreeViewID="TreeView1"runat="server"ImageSet="Msdn"NodeIndent="10"OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"ShowCheckBoxes="All"> <ParentNodeStyleFont-Bold="False"/> <HoverNodeStyleBackColor="#CCCCCC"BorderColor="#888888"BorderStyle="Solid"Font-Underline="True"/> <SelectedNodeStyleBackColor="White"BorderColor="#888888"BorderStyle="Solid"BorderWidth="1px" Font-Underline="False"HorizontalPadding="3px"VerticalPadding="1px"/> <NodeStyleFont-Names="Verdana"Font-Size="8pt"ForeColor="Black"HorizontalPadding="5px" NodeSpacing="1px"VerticalPadding="2px"/> </asp:TreeView> <asp:ImageID="Image1"runat="server"AlternateText="检索图片"Height="100px"Width="100px"/>&nbsp; </div> <asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="删除所选"/> </form> </body> </html>

呵呵,一个简单的文件管理器就做好了^.^;

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页