一、创建文件夹 using System.IO; string name = "aa"; string path = Server.MapPath("") + "//" + name; if (Directory.Exists(path)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件夹已存在了!');history.go(-1); // --></mce:script>"); } else { DirectoryInfo folder=Directory.CreateDirectory(path); string time = Convert.ToString(Directory.GetCreationTime(path)); string foldername = name.Substring(name.LastIndexOf("//") + 1); Response.Write("添加成功!"); Response.Write("添加时间:"+time); Response.Write("文件夹名:"+foldername); } 二、删除文件夹 using System.IO; string name = "aa"; string path = Server.MapPath("") + "//" + name; if (Directory.Exists(path)) { Directory.Delete(path); Response.Write(" 删除成功!"); } else { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件夹不存在!');history.go(-1); // --></mce:script>"); } 三、文件夹的移动 string name1 = "aa"; string name2 = "bb//aa"; //移动到的文件夹里,把AA移动到BB里 string path1 = Server.MapPath("") + "//" + name1; string path2 = Server.MapPath("") + "//" + name2; if (!Directory.Exists(path1)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件夹"+name1+"不存在!');history.go(-1); // --></mce:script>"); return; } if (Directory.Exists(path2)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件夹" + name2 + "已存在!');history.go(-1); // --></mce:script>"); return; } try { Directory.Move(path1, path2); Response.Write(" 文件夹移动成功!"); } catch { Response.Write("<mce:script type="text/javascript"><!-- alert(' 必须在同一目录下操作!');history.go(-1); // --></mce:script>"); } 四、获取文件夹下的文件列表 前台 <aspistBox ID="list" runat="server" Width="200px" Height="300px" Visible="false"></aspistBox> 后台 string name = "aa"; string path = Server.MapPath("") + "//" + name; if (!Directory.Exists(path)) { list.Visible = false; Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件夹" + name + "不存在!');history.go(-1); // --></mce:script>"); return; } else { DirectoryInfo foldinfo = new DirectoryInfo(path); FileSystemInfo[] dirs = foldinfo.GetFileSystemInfos(); if (dirs.Length < 1) { Response.Write("<mce:script type="text/javascript"><!-- alert('文件夹中没数据!');history.go(-1); // --></mce:script>"); return; } list.Visible = true; list.DataSource = dirs; list.DataBind(); } 五、创建文件 string name = "aa.aspx"; string path = Server.MapPath("") + "//" + name; if (File.Exists(path)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件" + name + "已存在!');history.go(-1); // --></mce:script>"); return; } else { FileStream fs = File.Create(path); fs.Close(); Response.Write(" 文件" + name + "添加成功!"); } 六、拷贝文件 string name1 = "aa//1.html"; string name2 = "bb//1.html"; string path1 = Server.MapPath("") + "//" + name1; string path2 = Server.MapPath("") + "//" + name2; if (!File.Exists(path1)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件" + name1 + "不存在!');history.go(-1); // --></mce:script>"); return; } if (File.Exists(path2)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件" + name2 + "已存在!');history.go(-1); // --></mce:script>"); return; } try { File.Copy(path1, path2); Response.Write(" 拷贝成功!"); } catch { Response.Write(" 拷贝失败!"); } 七、移动文件 string name1 = "aa//1.html"; string name2 = "bb//1.html"; string path1 = Server.MapPath("") + "//" + name1; string path2 = Server.MapPath("") + "//" + name2; if (!File.Exists(path1)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件" + name1 + "不存在!');history.go(-1); // --></mce:script>"); return; } if (File.Exists(path2)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件" + name2 + "已存在!');history.go(-1); // --></mce:script>"); return; } try { File.Move(path1, path2); Response.Write(" 移动成功!"); } catch { Response.Write(" 移动失败!"); } 八、文件删除 string name = "bb//1.html"; string path = Server.MapPath("") + "//" + name; if (!File.Exists(path)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件" + name + "不存在!');history.go(-1); // --></mce:script>"); return; } try { File.Delete(path); Response.Write(" 删除成功!"); } catch { Response.Write(" 删除失败!"); } 九、获取文件的详细信息 string name = "aa//11.txt"; string path = Server.MapPath("") + "//" + name; if (!File.Exists(path)) { Response.Write("<mce:script type="text/javascript"><!-- alert(' 文件" + name + "不存在!');history.go(-1); // --></mce:script>"); return; } else { FileInfo file = new FileInfo(path); string filexinxi1, filexinxi2, filexinxi3, filexinxi4, filexinxi5; //文件路径 filexinxi1 = file.FullName; //文件大小,字节 filexinxi2 = file.Length+"字节"; //文件属性 filexinxi3 = file.Attributes.ToString(); //文件创建时间 filexinxi4 = file.CreationTime.ToShortDateString(); //文件上次访问时间 filexinxi5 = file.LastAccessTime.ToShortDateString(); Response.Write(" 文件路径:"+filexinxi1+"<br>"); Response.Write(" 文件大小:" + filexinxi2 + "<br>"); Response.Write(" 文件属性:" + filexinxi3 + "<br>"); Response.Write(" 文件创建时间:" + filexinxi4 + "<br>"); Response.Write(" 文件上次访问时间:" + filexinxi5 + "<br>"); }