//获取路径
string dictionName = Server.MapPath(\ if (!Directory.Exists(dictionName)) {
//根据获取到的路径创建目录
Directory.CreateDirectory(dictionName); initFenleis(); } }
分类列表使用了一个asp.net 的Repeater控件
前台控件代码:
<%#Container.ItemIndex + 1 %>
<%#GetDataItem()%>
OnClientClick=\删除分类后将连分类内的图片一起删除确认要删除吗?')\删|?除y
- 22 -
后台数据绑定代码: public void initFenleis() {
string[] dict = getFenlei(); for (int i = 0; i < dict.Length;i++ ) {
dict[i] = dict[i].Substring(dict[i].LastIndexOf(\dict[i].Length - dict[i].LastIndexOf(\ }
Repeater1.DataSource = dict; Repeater1.DataBind();
}
//获取分类列表 public string[] getFenlei() {
string filepath = Server.MapPath(\
string[] filenames = Directory.GetDirectories(filepath); return filenames; }
点删除时调用的代码:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) {
if (e.CommandName.Equals(\ {
string dic = e.CommandArgument.ToString(); DeleteFolderAll(Server.MapPath(\ }
initFenleis(); }
//初始化分类列表
- 23 -
///
/// 删除文件夹及其内容 ///
///
public static void DeleteFolderAll(string dir) {
foreach (string d in Directory.GetFileSystemEntries(dir)) {
if (File.Exists(d)) {
FileInfo fi = new FileInfo(d);
if (fi.Attributes.ToString().IndexOf(\ fi.Attributes = FileAttributes.Normal; File.Delete(d);//直接删除其中的文件 } else {
DeleteFolder(d);////递归删除子文件夹 Directory.Delete(d); } }
Directory.Delete(dir); }
///
/// 清空指定的文件夹但不删文件夹 ///
///
public static void DeleteFolder(string dir) {
foreach (string d in Directory.GetFileSystemEntries(dir)) {
- 24 -
if (File.Exists(d)) {
FileInfo fi = new FileInfo(d);
if (fi.Attributes.ToString().IndexOf(\ fi.Attributes = FileAttributes.Normal; File.Delete(d);//直接删除其中的文件 } else {
DirectoryInfo d1 = new DirectoryInfo(d); if (d1.GetFiles().Length != 0) {
DeleteFolder(d1.FullName);////递归删除子文件夹 }
Directory.Delete(d); } }
} CSS:
.divTab{position:relative; top:2px; margin-left:10px;}
.divContent {
-webkit-box-shadow:0px 0px 10px #ddd; -moz-box-shadow:0px 0px 10px #ddd; box-shadow:0px 0px 10px #ddd; }
.divTab a{ text-shadow:1px 1px 5px #999; display:block; float:left; margin-right:5px; border:solid 2px #ddd; padding:0px 10px;
-webkit-border-top-left-radius:5px;
- 25 -
-webkit-border-top-right-radius:5px;
background-color:#eff; color:gray; text-decoration:none; cursor:pointer; }
.divTab a:hover{background-color:#fef;}
.divTab .aCur{ border-bottom:solid 2px white; background-color:white; color:blue; cursor:default; }
.divTab .aCur:hover { background-color:white; } table {
*border-collapse: collapse; /* IE7 and lower */ border-spacing: 0; width: 100%; }
.bordered {
border: solid #ccc 1px; -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px;
-webkit-box-shadow: 0 1px 1px #ccc; -moz-box-shadow: 0 1px 1px #ccc; box-shadow: 0 1px 1px #ccc; }
.bordered tr:hover { background: #fbf8e9;
-o-transition: all 0.1s ease-in-out;
- 26 -