Delete sample:(Note copy form ms-help:)
using System;
using System.IO;public class DeleteTest {
public static void Main() { // make a reference to a directory
DirectoryInfo di = new DirectoryInfo("TempDir"); // create the directory, only if it doesn't exist
if (di.Exists == false)
di.Create(); // create a subdirectory in the directory just created
DirectoryInfo dis = di.CreateSubdirectory("SubDir"); // process that directory as required
// ... // delete the subdirectory. The true indicates that if subdirectories
// or files are in this directory, delete them as well
dis.Delete(true); // delete the directory
di.Delete(true);
}
}
using System;
using System.IO;public class DeleteTest {
public static void Main() { // make a reference to a directory
DirectoryInfo di = new DirectoryInfo("TempDir"); // create the directory, only if it doesn't exist
if (di.Exists == false)
di.Create(); // create a subdirectory in the directory just created
DirectoryInfo dis = di.CreateSubdirectory("SubDir"); // process that directory as required
// ... // delete the subdirectory. The true indicates that if subdirectories
// or files are in this directory, delete them as well
dis.Delete(true); // delete the directory
di.Delete(true);
}
}
{
try
{
DirectoryInfo di = new DirectoryInfo(strAppPath);
di.Delete(true);
}
catch
{}
}
用DROP DATABASE
sqlCommand s=new sqlcommand("drop database database1",connectstr)s.executenoquery();
DirectoryInfo di = new DirectoryInfo(sPath);
di.Delete()删除文件
FileInfo fi=new FileInfo(fileName);
fi.Delete();删除数据库
sqlCommand cmd=new sqlcommand("drop database database1",connectstr)cmd.executenoquery();新的虚拟目录"Aspcn":
DirectoryEntry newVirDir = rootfolder.Children.Add("Aspcn","IIsWebVirtualDir");
newVirDir.Invoke("AppCreate",true);
newVirDir.CommitChanges();
rootfolder.CommitChanges();
删除虚拟目录的方法也很简单,就是找到你要删除的虚拟目录,然后调用AppDelete方法。
DirectoryEntry de = rootfolder.Children.Find("Aspcn","IIsVirtualDir");
de.Invoke("AppDelete",true);
rootfolder.CommitChanges();
删除文件:system.io.file.delete(文件路径,true)
删除数据库
sqlCommand s=new sqlcommand("drop database database1",connectstr)
s.executenoquery();
private void Button3_Click(object sender, System.EventArgs e)
{
if(!IsNullDel())
{
string TempUrl="D:/JDK/"+UserID+"/"+DelFloder.Text.Trim();
if(Directory.Exists(TempUrl))
{
Directory.Delete(TempUrl,true);
ListDirectory();
}
else
{
Response.Write("<script> alert(\"此文件夹不存在!!\")");
Response.Write("<"+"/script>");
}
}
}
备注:其中方法IsNullDel()是用来判断是否存在这个文件夹