protected void Button1_Click(object sender, EventArgs e)
{
///查询指定文件夹下所有文件
string path = Server.MapPath("Management/Upload/");
DirectoryInfo di = new DirectoryInfo(path);
//找到该目录下的文件
//FileInfo[] fis = di.GetFiles();
//foreach (FileInfo fi in fis)
//{
// Response.Write(fi.Name);//文件名称 不包含文件夹
// Response.Write(fi.Length);//文件大小
// Response.Write(fi.FullName);//文件名称路径
// Response.Write("<br>");
//}
//找到该目录下的文件夹
foreach (DirectoryInfo sub in di.GetDirectories())
{
Response.Write(sub.Name);
}
//添加指定文件到指定文件夹
//string g = "[SC_Brand_YouHuiQuan]" + Guid.NewGuid().ToString("N");
//CreateFolder(g);
//CopyFile("Management/Upload/default.jpg", "Management/Upload/" + g + "/default.jpg");
}
public static void CreateFolder(string FolderPathName)
{
if (FolderPathName.Trim().Length > 0)
{
try
{
string CreatePath = System.Web.HttpContext.Current.Server.MapPath("Management/Upload/" + FolderPathName).ToString();
if (!Directory.Exists(CreatePath))
{
Directory.CreateDirectory(CreatePath);
}
}
catch
{
throw;
}
}
}
public void CopyFile(string SourceFile, string ObjectFile)
{
string sourceFile = Server.MapPath(SourceFile);
string objectFile = Server.MapPath(ObjectFile);
if (System.IO.File.Exists(sourceFile))
{
System.IO.File.Copy(sourceFile, objectFile, true);
}
}